Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

programs

53 views

Published on

  • Be the first to comment

  • Be the first to like this

programs

  1. 1. #include<stdio.h> void main() { int A[200]={0,1}; int i,j,k,h,n=2,s=0,m; clrscr(); printf("Put a number for sum of the digits of its factorial.n"); scanf("%d",&m); for(i=2;i<=m;i++) { h=0; for(j=n-1;j>=0;j--) { k=A[j]*i+h; A[j+2]=k%10; h=k/10; } A[1]=h%10; A[0]=h/10; n=n+2; } printf("nnn"); for(i=0;i<2*m;i++) s=s+A[i]; printf("The sum of the digits is %d",s); getch(); } SUM OF FACTORIAL DIGITS 1
  2. 2. #include<stdio.h> void main() { int A[400]={1,0,2,4}; int i,j,k,h,n=4,s=0,m=100; clrscr(); for(i=2;i<=m;i++) { h=0; for(j=n-1;j>=0;j--) { k=A[j]*1024+h; A[j+4]=k%10; h=k/10; } A[3]=h%10; h=h/10; A[2]=h%10; h=h/10; A[1]=h%10; A[0]=h/10; n=n+4; } printf("nnn"); for(i=0;i<4*m;i++) s=s+A[i]; printf("The sum of the digits is %d",s); getch(); } POWER DIGIT SUM 2
  3. 3. #include<stdio.h> void main() { int i=0,j,p,temp,A[10]={0,1,2,3,4,5,6,7,8,9}; long int f,k=1,M=1000000; long int fact(int); clrscr(); while((k!=0)&&(i<9)) { f=fact(9-i); p=M/f; k=M%f; M=k; if(p>0) { if(k==0) p=p-1; temp=A[p+i]; for(j=p+i;j>i;j--) A[j]=A[j-1]; A[i]=temp; } i++; } printf("nnThe required number is:t"); for(j=0;j<i;j++) printf("%d",A[j]); for(j=9;j>=i;j--) printf("%d",A[j]); getch(); } long int fact(int m) { long int r=1; if(m==0) return(r); else return(m*fact(m-1)); } LEXICOGRAPHIC PERMUTATIONS 3
  4. 4. #include<stdio.h> void main() { int n,m,i; long int s=0; int d(int); clrscr(); printf("Input an upper bound.n"); scanf("%d",&n); for(i=12;i<=n;i++) { m=d(i); if((m>i)&&(i==d(m))) { if(m>n) m=0; s=s+m+i; } } printf("nnThe sum is :%ld.",s); getch(); } int d(int a) { int r=0,j; for(j=1;j<a;j++) { if(a%j==0) r=r+j; } return(r); } AMICABLE NUMBERS 4
  5. 5. #include<stdio.h> void main() { int A[200]={0,1}; int i,j,k,h,n=2,s=0,m; clrscr(); printf("Put a number for sum of the digits of its factorial.n"); scanf("%d",&m); for(i=2;i<=m;i++) { h=0; for(j=n-1;j>=0;j--) { k=A[j]*i+h; A[j+2]=k%10; h=k/10; } A[1]=h%10; A[0]=h/10; n=n+2; } printf("nnn"); i=0; while(1) { if(A[i]!=0) break; i++; } printf("nnThe factorial of %d is :nn",m); for(j=i;j<2*m;j++) { printf("%d",A[j]); s=s+A[j]; } printf("nnThe number of digits is %d.",2*m-i); printf("nnThe sum of the digits is %d",s); getch(); } SUM OF FACTORIAL DIGITS 5
  6. 6. Put a number for sum of the digits of its factorial. 100 The factorial of 100 is : 9332621544394415268169923885626670049071596826438162146859296389521759999322991 5608941463976156518286253697920827223758251185210916864000000000000000000000000 The number of digits is 158. The sum of the digits is 648 Put a number for sum of the digits of its factorial. 20 The factorial of 20 is : 2432902008176640000 The number of digits is 19. The sum of the digits is 54 Put a number for sum of the digits of its factorial. 10 The factorial of 10 is : 3628800 The number of digits is 7. The sum of the digits is 27 OUTPUT-1 OUTPUT-2 OUTPUT-3 6
  7. 7. #include<stdio.h> #include<math.h> void main() { int A[404]={0},i,j,k,h,n,p,q,s=0,m,d; clrscr(); printf("Input the power.n"); scanf("%d",&p); q=p%10; m=p/10; d=pow(2,q); if(q<4) { n=1; A[0]=d; } else if(q<7) { n=2; A[1]=d%10; A[0]=d/10; } else { n=3; A[2]=d%10; d=d/10; A[1]=d%10; A[0]=d/10; } for(i=1;i<=m;i++) { h=0; for(j=n-1;j>=0;j--) { k=A[j]*1024+h; A[j+4]=k%10; h=k/10; } A[3]=h%10; h=h/10; A[2]=h%10; h=h/10; A[1]=h%10; A[0]=h/10; n=n+4; } j=403; while(1) { if(A[j]!=0) break; j--; } k=0; while(1) { if(A[k]!=0) break; k++; } printf("nnnThe number 2 raised to %d is :nn",p); for(i=k;i<=j;i++) POWER DIGIT SUM 7
  8. 8. { printf("%d",A[i]); s=s+A[i]; } printf("nnThe number of digits is %d.nn",j-k+1); printf("The sum of the digits is %d",s); getch(); } 8
  9. 9. Input the power. 1000 The number 2 raised to 1000 is : 107150860718626732094842504906000181056140481170553360744375038837035105112493612249 319837881569585812759467291755314682518714528569231404359845775746985748039345677748 242309854210746050623711418779541821530464749835819412673987675591655439460770629145 71196477686542167660429831652624386837205668069376 The number of digits is 302. The sum of the digits is 1366 Input the power. 20 The number 2 raised to 20 is : 1048576 The number of digits is 7. The sum of the digits is 31 Input the power. 5 The number 2 raised to 5 is : 32 The number of digits is 2. The sum of the digits is 5 OUTPUT-1 OUTPUT-2 OUTPUT-3 9
  10. 10. #include<stdio.h> void main() { int i=0,j,p,temp,A[10]={0,1,2,3,4,5,6,7,8,9}; long int f,k=1,M,q; long int fact(int); clrscr(); printf("nnInput the lexicographic ordinal status. "); scanf("%ld",&M); printf("nnInput the number of digits using. "); scanf("%d",&q); f=fact(q); if(M>f) printf("nnThere are only %ld numbers in the list.",f); else { while((k!=0)&&(i<q-1)) { f=fact(q-i-1); p=M/f; k=M%f; M=k; if(p>0) { if(k==0) p=p-1; temp=A[p+i]; for(j=p+i;j>i;j--) A[j]=A[j-1]; A[i]=temp; } i++; } printf("nnThe required number is:t"); for(j=0;j<i;j++) printf("%d",A[j]); for(j=q-1;j>=i;j--) printf("%d",A[j]); } getch(); } long int fact(int m) { long int r=1; if(m==0) return(r); else return(m*fact(m-1)); } LEXICOGRAPHIC PERMUTATIONS 10
  11. 11. Input the lexicographic ordinal status. 1000000 Input the number of digits using. 10 The required number is: 2783915460 Input the lexicographic ordinal status. 5 Input the number of digits using. 3 The required number is: 201 Input the lexicographic ordinal status. 4000000 Input the number of digits using. 10 There are only 3628800 numbers in the list. OUTPUT-1 OUTPUT-2 OUTPUT-3 11
  12. 12. #include<stdio.h> void main() { int n,m,i; long int s=0; int d(int); clrscr(); printf("Input an upper bound.n"); scanf("%d",&n); printf("nnThe amicable pairs are :nn"); for(i=12;i<=n;i++) { m=d(i); if((m>i)&&(i==d(m))) { printf("%dt%dnn",i,m); if(m>n) m=0; s=s+m+i; } } printf("nnThe sum of the amicable numbers below %d is :%ld.",n,s); getch(); } int d(int a) { int r=0,j; for(j=1;j<a;j++) { if(a%j==0) r=r+j; } return(r); } AMICABLE NUMBERS 12
  13. 13. Input an upper bound. 10000 The amicable pairs are : 220 284 1184 1210 2620 2924 5020 5564 6232 6368 The sum of the amicable numbers below 10000 is :31626. Input an upper bound. 250 The amicable pairs are : 220 284 The sum of the amicable numbers below 250 is :220. Input an upper bound. 500 The amicable pairs are : 220 284 The sum of the amicable numbers below 500 is :504. OUTPUT-1 OUTPUT-2 OUTPUT-3 13
  14. 14. #include<stdio.h> #include<math.h> int m=1; void main() { long int p,q; int i,j,k,n,r=1,A[5000]={1},s=0; long int pro(int); clrscr(); printf("Input a number for the sum of its factorial digits.nn"); scanf("%d",&n); while(m<=n) { p=pro(n); q=0; for(k=0;k<r;k++) { q=A[k]*p+q; A[k]=q%10; q=q/10; } while(q!=0) { A[k]=q%10; q=q/10; k++; } r=k; } printf("nnThe factorial of %d is :nn",n); for(i=r-1;i>=0;i--) { printf("%d",A[i]); s=s+A[i]; } printf("nnThe number of digits is %d.nn",r); printf("The sum of the digits is %d.",s); getch(); } long int pro(int a) { long int l=1,b; b=pow(2,26); while((l<=b/m)&&(m<=a)) { l=l*m; m++; } return(l); } SUM OF FACTORIAL DIGITS 14
  15. 15. #include<stdio.h> #include<math.h> void main() { long int p,q; int i,j=0,k,l,m,n=1,A[310]={1},s=0; clrscr(); printf("Input the power.n"); scanf("%d",&m); l=m/27; p=pow(2,27); for(i=0;i<2;i++) { while(j<l) { q=0; for(k=0;k<n;k++) { q=A[k]*p+q; A[k]=q%10; q=q/10; } while(q!=0) { A[k]=q%10; q=q/10; k++; } n=k; j++; } j--; p=pow(2,m%27); } printf("The number 2 raised to %d is :nn",m); for(i=n-1;i>=0;i--) { printf("%d",A[i]); s=s+A[i]; } printf("nnThe number of digits is %d.nn",n); printf("The sum of the digits is %d.",s); getch(); } POWER DIGIT SUM 15

×