19. a+a²+a³+a⁴+a⁵... :—
#include<stdio.h>
int main()
{
int i,n,a,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0;
for(i=1;i<=n;i++)
{
sum=sum+pow(a,i);
}
printf("%d",sum);
return 0;
}
19. a+a²+a³+a⁴+a⁵... :—
#include<stdio.h>
int main()
{
int i,n,a,sum;
printf("enter value of n and a ");
scanf("%d%d",&n,&a);
sum=0;
for(i=1;i<=n;i++)
{
sum=sum+pow(a,i);
}
printf("%d",sum);
return 0;
}
18.1!-2!+3!-4!+...n :—
#include<stdio.h>
int main()
{
int i,f,n,s,sum;
printf("enter a value of n ");
scanf("%d",&n);
sum=0,f=1,s=-1;
for(i=1;i<=n;i++)
{
s=s*-1;
f=f*i;
sum=sum+f*s;
}
printf("%d",sum);
return 0;
}
17. 1!+2!+3!+...n :—
#include<stdio.h>
int main()
{
int i,f,n,sum;
printf("enter a value of n ");
scanf("%d",&n);
sum=0,f=1;
for(i=1;i<=n;i++)
{
f=f*i;
sum=sum+f;
}
printf("%d",sum);
return 0;
}
16. Input a number and check it is palindrome or not :—
#include<stdio.h>
int main()
{
int r,n,k,rev;
printf("enter a number ");
scanf("%d",&n);
k=n;
rev=0;
while(k>0)
{
r=k%10;
k=k/10;
rev=rev*10+r;
}
if(n==rev)
{
printf("%d is a palindrome",n);
}
else
{
printf("%d is not a palindrome",n);
}
return 0;
}
15. Sum of digits :—
#include<stdio.h>
int main()
{
int r,n,sum;
printf("enter a value of n ");
scanf("%d",&n);
sum=0;
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("%d",sum);
return 0;
}
14. Print the digit in reverse :—
#include<stdio.h>
int main()
{
int r,n;
printf("enter a value of n ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
printf("%d",r);
n=n/10;
}
return 0;
}
13.Print : 10 9 8 7 ... 1 :—
#include<stdio.h>
int main()
{
int i;
for(i=10;i>=1;i--)
{
printf("%d ",i);
}
return 0;
}
12. Print : 0 10 20 30 ... 100 :—
#include<stdio.h>
int main()
{
int i;
for(i=0;i<=100;i+=10)
{
printf("%d ",i);
}
return 0;
}
11. 100+95+90+...+0 :—
#include<stdio.h>
int main()
{
int i,sum;
sum=0;
for(i=100;i>=0;i-=5)
{
sum=sum+i;
}
printf("%d",sum);
return 0;
}
10. 0 7 26 ... 999
=(1³-1) (2³-1) (3³-1) ... (10³-1) :—
#include<stdio.h>
int main()
{
int i,sum;
sum=0;
for(i=1;i<=10;i++)
{
sum=sum+i*i*i-1;
}
printf("%d",sum);
return 0;
}