C PROGRAMS : CONTROL STRUCTURES

C PROGRAMS : CONTROL STRUCTURES
17.Program to print the fibonacii series till which user wishes
/*
 Fibonacii series: Fibonacii series is one in which the nth term is 
 sum of (n-1)th term and (n-2)th term.
 The first two numbers of series are 0 and 1
 For example: 0 1 1 2 3 5 8 13 21 and so on
 */
 
 #include<stdio.h>
 #include<conio.h> // Linux user - Remove this

 int main()
 {
  /* Declaring variable for n=number, f=first, s=second, 
  t=third number, i=to iterate the loop */
  int n,f,s,t,i;
  
  // Inputing number till where fibonacci series is to be displayed
  printf("Enter the number till which you want to see fibonacci series:");
  scanf("%d",&n);
  
  // Determining and displaying fibonacii series
  printf("Fibonacii Series: ");
  
  f=0;
  s=1;
  printf("%d %d ",f,s);
  for(i=3;i<=n;i++)
  {
   t=f+s;
   printf("%d ",t);
   f=s;
   s=t;
  }
  getch(); // Linux user - Remove this

  return 0;
 }

17. Program to determine whether entered character is capital case letter, small case letter, a digit or a special symbol
#include<stdio.h>
#include<conio.h> // Linux user - Remove this

int main()
{
 // Declaring variable for c=character
 char c;
 
 // Inputing character
 printf("Enter any character: ");
 scanf("%c",&c);
 
 if(c>=65 && c<=90)
 printf("Character is Upper Case Letter");
 else if(c>=97 && c<=122)
 printf("Character is Lower Case Letter");
 else if(c>=48 && c<=57)
 printf("Character is a Digit");
 else
 printf("Character is Special Symbol");
 
 getch(); // Linux user - Remove this

 return 0;
}
18.Program to find whether a number is Perfect Square or Not
/*
A perfect square is a number that can be expressed as the product of two equal integers.

9
9 is a perfect square becuase it can be expressed as 3 * 3 (product of two equal integers)
16
16 is a perfect square becuase it can be expressed as 4 * 4 (product of two equal integers)
25
25 is a perfect square becuase it can be expressed as 5 * 5 (product of two equal integers)
*/

#include<stdio.h>
#include<conio.h> // Linux user - Remove this

int main()
{
 //Declaring variable for n=number
 int n;
 
 // Declaring variable for r=remainder, q=uotient, i=to iterate the loop
 int r=0,q=0,i,flag=0;
 
 // Inputting Number
 printf("Enter any numbre: ");
 scanf("%d",&n);
 
 // Determin whether Numbr is Perfect Square or Not
 for(i=1;i<=n;i++)
 {
  r=n%i;
  q=n/i;
  if(r==0 && i==q)
  {
   flag=1;
   break;
  }
 }
 
 // Displaying Result
 if(flag==1)
 printf("Number is Perfect Square");
 else
 printf("Number is not Perfect Square");
 
 getch(); // Linux user - Remove this

 return 0;
}

19.Program to print (list) Perfect Square Number between any two number and display it in the format
#include<stdio.h>
#include<conio.h> // Linux user - Remove this

int main()
{
 /* Declaring variable for r=remainder, q=uotient, i,
 m=to iterate the loops, f1=Another flag variable */
 int r=0, q=0, i, flag=0, f1=0, m;
 
 // Delcaring variable for s=start point, e=endpoint
 int s,e;
 
 // Inputting start point and end point
 printf("Enter from where you want to list perfect Number:");
 scanf("%d",&s);
 printf("Enter till where you want to list perfect Number:");
 scanf("%d",&e);
 
 // Determin Number is Perfect or Not
 for(m=s;m<=e;m++)
 {
  flag=0;
 for(i=1;i<=m;i++)
 {
  r=m%i;
  q=m/i;
  if(r==0 && i==q)
  {
   f1=1;
   flag=1;
   break;
  }
 }
 
 // Displaying Perfect Square Numbre in the given format
 if(flag==1)
 printf("%d is a Perfect Square because it can be expressed as: %d * %d \n",m,i,i);
  }
  
 /* Checking if any Perfect Square Number exist and if not 
 then displaying appropriate message */   
 if(f1==0)
 printf("No Perfect Square Number exist");
 
 getch(); // Linux user - Remove this

 return 0;
}

20. Program for Bank account Handling
A customer maintains a saving account in a bank. The bank provide an interest rate of 
simple interest of 4% per annum. Write a program displaying a menu to let the user enter 
the coice as follows: 
1 : Deposit an amount A
2 : Withdrawl of amount A
3 : Displaying the balance amount
4 : Calculating interest for d days on balance amount
5 : Exit
Fix initial balance amount = 1000
*/

#include<stdio.h>
#include<conio.h> // Linux user - Remove this

int main()
{
 // Declaring variable for a=amount, ba=balance amount, si=simple interest
 float a, ba=1000, si;
 
 /* Declaring variable for ch=choice, d=day, ans=checks if user 
 want to enter another query or choice */
 int ch, d,ans;
 
 // Displaying choices
 printf("Bank Queries:\n");
 printf("1 : Deposit an amount\n");
 printf("2 : Withdrawl of amount\n");
 printf("3 : Displaying the balance amount\n");
 printf("4 : Calculating interest for d days on balance amount\n");
 printf("5 : exit\n\n");
 
 do
 {
 // Inputing choices
 printf("Enter your query:");
 scanf("%d",&ch);
 
 // Performing various bank queries
 switch(ch)
 {
  case 1:
   // Inputing deposit amount
   printf("Enter amount to be deposited:");
   scanf("%f",&a);
   ba=ba+a;
   break;
  case 2:
   // Inputing withdrawl amount
   printf("Enter withdrawl amount:");
   scanf("%f",&a);
   ba=ba-a;
   break;
  case 3:
   printf("Balance Amount: %f\n",ba);
   break;
  case 4:
   // Inputing days
   printf("Enter Days for which you want to calculate interest:");
   scanf("%d",&d);
   
   // Calculating simple interest
   si=(a*0.04*d)/100;
   printf("Simple interest=%f\n",si);
   ba=ba+si;
   break;
  case 5:
   printf("Press any key to exit");
   getch();
   exit(0);
   break;
   default:
    printf("Wrong Entry");
 }
 printf("Do you want to enter another query: 1-yes, 2-no : ");
 scanf("%d",&ans);
  }while(ans==1);
 
 printf("Press any key to exit");
 
 getch(); // Linux user - Remove this

 return 0;
}

Share this

Related Posts

Previous
Next Post »