Download presentation
Presentation is loading. Please wait.
Published byPatricia Dickerson Modified over 9 years ago
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"); printf("\nEnter the choice:"); scanf("%d",&n);
2
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;
3
case 3: c=a*b; printf("\nThe result of Multiplication is:%d",c); break; case 0: exit(0); break; } getch(); }
4
Output Enter the value of a,b:5 6 MENU 1.ADD 2.SUB 3.MULTIPLY 0.EXIT Enter the choice:1 The result of Addition is:11
5
Finding Armstrong No #include 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; }
6
if(a==sum) { printf("\nIt is an armstrong number"); } else { printf("\nIt is not an armstrong number"); } getch(); }
7
Output Enter the number:153 It is an armstrong number
8
Sum of the Digits #include void main() { int r=0,sum=0,n; printf("\nEnter the no:"); scanf("%d",&n); while(n>0) { r=n%10;
9
sum=sum+r; n=n/10; } printf("sum of the digits is:%d",sum); }
10
Output Enter the no:156 sum of the digits is:12
11
Reverse of a number #include void main() { int r=0,sum=0,n; printf("\nEnter the no:"); scanf("%d",&n); while(n>0)
12
{ r=n%10; sum=sum*10+r; n=n/10; } printf("Reverse of the number is:%d",sum); getch(); }
13
Output Enter the no:567 Reverse of the number is:765
14
Fibonacci Series #include void main() { int f=0,f1=-1,f2=1,n,i; printf("\nEnter the number:"); scanf("%d",&n);
15
while(f<n) { f=f1+f2; f1=f2; f2=f; printf("\t%d",f); } getch(); }
16
Output Enter the number:5 0 1 1 2 3 5
17
Swapping #include 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;
18
printf(" \nThe value of a is:%d",a); printf(" \nThe value of b is:%d",b); getch( ); } Output: Enter the value of a:5 Enter the value of b:4 The value of a is:4 The value of b is:5
19
Swapping without using third variable #include void main ( ) { int a,b; clrscr( ); printf(" \nEnter the value of a:"); scanf("%d",&a); printf(" \nEnter the value of b:"); scanf("%d",&b);
20
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:5 Enter the value of b:6 The value of a is:6 The value of b is:5
21
Quadratic Equation #include 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;
22
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( ); }
23
Output Enter the value of a:4 Enter the value of b:5 Enter the value of c:6 The roots are imaginary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.