80 likes | 455 Views
ADDING DIGITS. #include< stdio.h > #include< conio.h > #include< math.h > void main() { unsigned long int a; int i,b,sum =0; clrscr (); printf ("enter a no. to add digits of"); scanf ("% lu",&a ); while(a>0) { b=a%10; sum= sum+b ; a=a/10; }
E N D
ADDING DIGITS #include<stdio.h> #include<conio.h> #include<math.h> void main() { unsigned long int a; inti,b,sum=0; clrscr(); printf("enter a no. to adddigits of"); scanf("%lu",&a); while(a>0) { b=a%10; sum=sum+b; a=a/10; } printf(“sumof digits is %d",sum); getch(); }
#include<stdio.h> #include<conio.h> #include<math.h> void main() { unsigned long inta,rev=0; int b; clrscr(); printf("enter a no. to reverse"); scanf("%lu",&a); while(a>0) { b=a%10; rev=rev*10+b; a=a/10; } printf("no. in reverse order%lu",rev); getch(); } REVERSE DIGITS TO CHECK WHETHER NO. IS SAME BEFORE & AFTER REVERSING: Declare org,org=a,at last if(org==rev) printf(“same”); else printf(“different”);
#include<stdio.h> #include<conio.h> #include<math.h> void main() { long int fact=1; int a; clrscr(); printf("enter a no. to find factorial of"); scanf("%d",&a); fact=a; for(a=a-1;a>1;a--) { fact=fact*a; } printf("factorial of no. is %ld",fact); getch(); } FACTORIAL
#include<stdio.h> #include<conio.h> #include<math.h> void main() { inta,i; clrscr(); printf("enter a no. to check prime or not"); scanf("%d",&a); for(i=2;i<a;i++) { if((a%i)==0) { printf("number is not prime"); goto end; } } printf("number is prime"); end: getch(); } PRIME NUMBER
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int a=0,b=1,sum,i,n; clrscr(); printf("enter a no. of terms in fibbonacci series"); scanf("%d",&n); printf("%d\t%d",a,b); for(i=0;i<=n-2;i++) { sum=a+b; printf("\t%d",sum); a=b; b=sum; } getch(); } FIBBONACCI SERIES