Write a program that determine the value of following series up-to n.
1+x+x2+x3+x4+………………………+xn
#include <stdio.h>
int main()
{
int x,n,ln,tn,psum=0,sum=0;
//clrscr();
printf("\n enter x and power n");
scanf("%d%d",&x,&ln);
sum=1;
n=1;
do
{
psum=1;
for(tn=1;tn<=n;tn++)
psum=psum*x;
n++;
sum=sum+psum;
}while(n<=ln);
printf("\n sum of given series =%d",sum);
//getch();
return 0;
}
output:
0 Comments
Post a Comment