Example #include void main() { int a,b,c,n; clrscr(); printf("\nEnter the value of a,b:");...

23
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);

Transcript of Example #include void main() { int a,b,c,n; clrscr(); printf("\nEnter the value of a,b:");...

Page 1: Example #include 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");

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);

Page 2: Example #include 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");

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;

Page 3: Example #include 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");

case 3:c=a*b;printf("\nThe result of Multiplication is:%d",c);break;

case 0:exit(0);break;

}getch();

}

Page 4: Example #include 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");

Output

Enter the value of a,b:56MENU1.ADD2.SUB3.MULTIPLY0.EXITEnter the choice:1The result of Addition is:11

Page 5: Example #include 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");

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;

}

Page 6: Example #include 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");

if(a==sum){ printf("\nIt is an armstrong number");}else{ printf("\nIt is not an armstrong number");}

getch();}

Page 7: Example #include 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");

Output

Enter the number:153It is an armstrong number

Page 8: Example #include 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");

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;

Page 9: Example #include 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");

sum=sum+r; n=n/10; } printf("sum of the digits is:%d",sum);}

Page 10: Example #include 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");

Output

Enter the no:156sum of the digits is:12

Page 11: Example #include 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");

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)

Page 12: Example #include 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");

{ r=n%10; sum=sum*10+r; n=n/10;

} printf("Reverse of the number is:%d",sum); getch();}

Page 13: Example #include 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");

Output

Enter the no:567Reverse of the number is:765

Page 14: Example #include 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");

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);

Page 15: Example #include 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");

while(f<n){ f=f1+f2;

f1=f2; f2=f;

printf("\t%d",f);}

getch();}

Page 16: Example #include 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");

Output

Enter the number:5 0 1 1 2 3 5

Page 17: Example #include 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");

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;

Page 18: Example #include 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(" \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

Page 19: Example #include 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");

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);

Page 20: Example #include 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");

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

Page 21: Example #include 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");

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;

Page 22: Example #include 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");

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( );}

Page 23: Example #include 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");

Output

Enter the value of a:4

Enter the value of b:5

Enter the value of c:6

The roots are imaginary