29. Print all factors of a number :—
#include<stdio.h>
int main()
{
int i,n,r;
printf("enter a value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
printf("%d",i);
}
}
return 0;
}
29. Print all factors of a number :—
#include<stdio.h>
int main()
{
int i,n,r;
printf("enter a value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
printf("%d",i);
}
}
return 0;
}
28. Armstrong number checking :—
#include<stdio.h>
int main()
{
int i,n,m,k,r,sum;
printf("enter value of n ");
scanf("%d",&n);
m=n;
k=0;
while(n>0)
{
n=n/10;
k++;
}
n=m;
sum=0;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+pow(r,k);
}
if(sum==m)
{
printf("It is an Armstrong number");
}
else
{
printf("It is not an Armstrong number");
}
return 0;
}
27. Count the total number of digits :—
#include<stdio.h>
int main()
{
int i,n,count;
printf("enter value of n ");
scanf("%d",&n);
count=0;
while(n>0)
{
n=n/10;
count++;
}
printf("%d",count);
return 0;
}
26. Sum of digits :—
#include<stdio.h>
int main()
{
int i,n,r,k,sum;
printf("enter value of n ");
scanf("%d",&n);
sum=0,k=n;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("%d",sum);
return 0;
}
25. (a²/2!)+(a⁴/4!)+(a⁶/6!)+... :—
#include<stdio.h>
int main()
{
int i,n,a,f,k,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0,f=1;
for(i=1;i<=n;i++)
{
k=2*i;
sum=sum+pow(a,k)/(float)f;
f=f*(k+1)*(k+2);
}
printf("%d",sum);
return 0;
}
24. a+(a³/3!)+(a⁵/5!)+... :—
#include<stdio.h>
int main()
{
int i,n,a,f,k,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0,f=1;
for(i=1;i<=n;i++)
{
k=2*i-1;
sum=sum+pow(a,k)/(float)f;
f=f*(k+1)*(k+2);
}
printf("%d",sum);
return 0;
}
23.a-(a²/2!)+(a³/3!)-(a⁴/4!)... :—
#include<stdio.h>
int main()
{
int i,n,a,f,s,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0,f=1,s=-1;
for(i=1;i<=n;i++)
{
f=f*i;
s=s*-1;
sum=sum+pow(a,i)*s/(float)f;
}
printf("%d",sum);
return 0;
}
22. (a/1!)+(a²/2!)+(a³/3!)+(a⁴/4!)+... :—
#include<stdio.h>
int main()
{
int i,n,a,f,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
sum=sum+pow(a,i)/(float)f;
}
printf("%d",sum);
return 0;
}
20. a-a²+a³-a⁴... :—
#include<stdio.h>
int main()
{
int i,n,a,s,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0,s=-1;
for(i=1;i<=n;i++)
{
s=s*-1;
sum=sum+pow(a,i)*s;
}
printf("%d",sum);
return 0;
}