Write a C program to read in two numbers, x and n, and then compute the sum of this geometric progression: 1+x+x2+x3+………….+xn.
#include<stdio.h>
int main()
{
int x,n,i;
long int s=1;
printf(“Enter x,n values : “);
scanf(“%d%d”,&x,&n);
for(i=1;i<=n;i++)
s=s+pow(x,i);
printf(“Result = %ld\n”,s);
return 0;
}
Output:
Enter x,n values : 10 6
Result = 1111111