example #include void main() { int a,b,c,n; clrscr(); printf("\nenter the value of a,b:");...
TRANSCRIPT
Example #include<stdio.h> #include<conio.h> void main() {
int a,b,c,n;clrscr();printf("\nEnter the value of a,b:");scanf("%d%d",&a,&b);printf("\nMENU");printf("\n1.ADD\n2.SUB\n3.MULTIPLY\n0.EXIT");printf("\nEnter the choice:");scanf("%d",&n);
switch(n){ case 1:
c=a+b;printf("\nThe result of Addition is:%d",c);break;
case 2:c=a-b;printf("\nThe result of Subtraction is:%d",c);break;
case 3:c=a*b;printf("\nThe result of Multiplication is:%d",c);break;
case 0:exit(0);break;
}getch();
}
Output
Enter the value of a,b:56MENU1.ADD2.SUB3.MULTIPLY0.EXITEnter the choice:1The result of Addition is:11
Finding Armstrong No#include<stdio.h>#include<conio.h>void main(){ int r=0,sum=0,n,a; printf("\nEnter the number:"); scanf("%d",&n); a=n;
while(n>0){
r=n%10;sum=sum+r*r*r;n=n/10;
}
if(a==sum){ printf("\nIt is an armstrong number");}else{ printf("\nIt is not an armstrong number");}
getch();}
Output
Enter the number:153It is an armstrong number
Sum of the Digits#include<stdio.h>#include<conio.h>void main(){ int r=0,sum=0,n; printf("\nEnter the no:"); scanf("%d",&n); while(n>0) { r=n%10;
sum=sum+r; n=n/10; } printf("sum of the digits is:%d",sum);}
Output
Enter the no:156sum of the digits is:12
Reverse of a number
#include<stdio.h>#include<conio.h>void main(){ int r=0,sum=0,n; printf("\nEnter the no:"); scanf("%d",&n); while(n>0)
{ r=n%10; sum=sum*10+r; n=n/10;
} printf("Reverse of the number is:%d",sum); getch();}
Output
Enter the no:567Reverse of the number is:765
Fibonacci Series
#include<stdio.h>#include<conio.h>void main(){int f=0,f1=-1,f2=1,n,i;printf("\nEnter the number:");scanf("%d",&n);
while(f<n){ f=f1+f2;
f1=f2; f2=f;
printf("\t%d",f);}
getch();}
Output
Enter the number:5 0 1 1 2 3 5
Swapping #include<stdio.h>#include <conio.h>void main ( ){int a,b,c;clrscr( );printf(" \nEnter the value of a:");scanf("%d",&a);printf(" \nEnter the value of b:");scanf("%d",&b);c=a;a=b;b=c;
printf(" \nThe value of a is:%d",a);printf(" \nThe value of b is:%d",b);getch( );}
Output:Enter the value of a:5Enter the value of b:4
The value of a is:4The value of b is:5
Swapping without using third variable
#include<stdio.h>#include <conio.h>void main ( ){int a,b;clrscr( );printf(" \nEnter the value of a:");scanf("%d",&a);printf(" \nEnter the value of b:");scanf("%d",&b);
a=a+b;b=a-b;a=a-b;printf(" \nThe value of a is:%d",a);printf(" \nThe value of b is:%d",b);getch( );}
Output:Enter the value of a:5Enter the value of b:6
The value of a is:6The value of b is:5
Quadratic Equation#include<stdio.h>#include <conio.h>#include<math.h>void main ( ){int a,b,c,d,r1,r2;clrscr( );printf(" \nEnter the value of a:");scanf("%d",&a);printf(" \nEnter the value of b:");scanf("%d",&b);printf(" \nEnter the value of c:");scanf("%d",&c);d=b*b-4*a*c;
if(d>=0){
r1=(-b+sqrt(d))/(2*a);r2=(-b-sqrt(d))/(2*a);
printf(" \nThe roots are %d,%d",r1,r2);}else{ printf(" \nThe roots are imaginary");}getch( );}
Output
Enter the value of a:4
Enter the value of b:5
Enter the value of c:6
The roots are imaginary