SlideShare a Scribd company logo
#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
#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
#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
#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
#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
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
#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
{
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
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
#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
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
#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
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
#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
#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

More Related Content

What's hot

Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
C basics
C basicsC basics
C basicsMSc CST
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structuresvinay arora
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
Nitesh Dubey
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Stringsvinay arora
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
University of Potsdam
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
C programms
C programmsC programms
C programms
Mukund Gandrakota
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.
Hazrat Bilal
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
 
Cpds lab
Cpds labCpds lab
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
Chhom Karath
 

What's hot (20)

Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C basics
C basicsC basics
C basics
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
Double linked list
Double linked listDouble linked list
Double linked list
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C programms
C programmsC programms
C programms
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Ds
DsDs
Ds
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 

Viewers also liked

Magickoven Bakery Coimbatore
Magickoven Bakery Coimbatore Magickoven Bakery Coimbatore
Magickoven Bakery Coimbatore
magickoven bakery
 
Trabajo práctico Informatica
Trabajo práctico InformaticaTrabajo práctico Informatica
Trabajo práctico Informatica
Agustina.b Brito
 
Autobiografia
AutobiografiaAutobiografia
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
Bharat Badre
 
Collage guzmán
Collage guzmánCollage guzmán
Collage guzmán
Lizzette Montserrat
 
Princess game-กัลยาณี
Princess game-กัลยาณีPrincess game-กัลยาณี
Princess game-กัลยาณี
Kanlayanee Yodput
 
Порівняльна таблиця деякі питання НАЗЯВО
Порівняльна таблиця  деякі питання НАЗЯВОПорівняльна таблиця  деякі питання НАЗЯВО
Порівняльна таблиця деякі питання НАЗЯВО
vasyl petrov
 
Questioons on Optics_ For CBSE Students
Questioons on Optics_ For CBSE StudentsQuestioons on Optics_ For CBSE Students
Questioons on Optics_ For CBSE Students
Physics Gurukul
 
Medicina
MedicinaMedicina
Medicina
felipe castillo
 
Merchant Program True Money - Complete
Merchant Program True Money - CompleteMerchant Program True Money - Complete
Merchant Program True Money - CompleteNovita Anugrah
 
JessicaPotter_WorkSample
JessicaPotter_WorkSampleJessicaPotter_WorkSample
JessicaPotter_WorkSampleJessica Potter
 
Ukrmova 8-klas-bondarenko
Ukrmova 8-klas-bondarenkoUkrmova 8-klas-bondarenko
Ukrmova 8-klas-bondarenko
kreidaros1
 
Ensayo 5 semestre de ingeniería comunicación no verval
Ensayo 5 semestre de ingeniería comunicación no vervalEnsayo 5 semestre de ingeniería comunicación no verval
Ensayo 5 semestre de ingeniería comunicación no verval
MARQUEZA ROBLES
 
¿Mariana inteligibilidad esquemas
¿Mariana inteligibilidad esquemas¿Mariana inteligibilidad esquemas
¿Mariana inteligibilidad esquemas
mariana ortiz
 

Viewers also liked (20)

Magickoven Bakery Coimbatore
Magickoven Bakery Coimbatore Magickoven Bakery Coimbatore
Magickoven Bakery Coimbatore
 
Trabajo práctico Informatica
Trabajo práctico InformaticaTrabajo práctico Informatica
Trabajo práctico Informatica
 
Autobiografia
AutobiografiaAutobiografia
Autobiografia
 
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
(by mr.akash kolamkar) Rajapeth amravati rob flyover amravati presentation ps...
 
project
projectproject
project
 
Collage guzmán
Collage guzmánCollage guzmán
Collage guzmán
 
Princess game-กัลยาณี
Princess game-กัลยาณีPrincess game-กัลยาณี
Princess game-กัลยาณี
 
Порівняльна таблиця деякі питання НАЗЯВО
Порівняльна таблиця  деякі питання НАЗЯВОПорівняльна таблиця  деякі питання НАЗЯВО
Порівняльна таблиця деякі питання НАЗЯВО
 
Questioons on Optics_ For CBSE Students
Questioons on Optics_ For CBSE StudentsQuestioons on Optics_ For CBSE Students
Questioons on Optics_ For CBSE Students
 
Partesdeuncomputador
Partesdeuncomputador Partesdeuncomputador
Partesdeuncomputador
 
Medicina
MedicinaMedicina
Medicina
 
Dt
DtDt
Dt
 
Merchant Program True Money - Complete
Merchant Program True Money - CompleteMerchant Program True Money - Complete
Merchant Program True Money - Complete
 
jfs-masters-1
jfs-masters-1jfs-masters-1
jfs-masters-1
 
Joann Resume
Joann ResumeJoann Resume
Joann Resume
 
Resume
ResumeResume
Resume
 
JessicaPotter_WorkSample
JessicaPotter_WorkSampleJessicaPotter_WorkSample
JessicaPotter_WorkSample
 
Ukrmova 8-klas-bondarenko
Ukrmova 8-klas-bondarenkoUkrmova 8-klas-bondarenko
Ukrmova 8-klas-bondarenko
 
Ensayo 5 semestre de ingeniería comunicación no verval
Ensayo 5 semestre de ingeniería comunicación no vervalEnsayo 5 semestre de ingeniería comunicación no verval
Ensayo 5 semestre de ingeniería comunicación no verval
 
¿Mariana inteligibilidad esquemas
¿Mariana inteligibilidad esquemas¿Mariana inteligibilidad esquemas
¿Mariana inteligibilidad esquemas
 

Similar to programs

L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
Syed Tanveer
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
Dr. Loganathan R
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
Rumman Ansari
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
Salar Delavar Qashqai
 
Arrays
ArraysArrays
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
C programs
C programsC programs
C programs
Koshy Geoji
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 

Similar to programs (20)

L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
array.ppt
array.pptarray.ppt
array.ppt
 
Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...Pushover analysis force analogy method with force control based on euler bern...
Pushover analysis force analogy method with force control based on euler bern...
 
Arrays
ArraysArrays
Arrays
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C programs
C programsC programs
C programs
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
C Programming
C ProgrammingC Programming
C Programming
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
week-5x
week-5xweek-5x
week-5x
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 

programs

  • 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. #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. #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. #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. #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. 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. #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. { 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. 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. #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. 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. #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. 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. #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. #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