Skip to main content
C program to find the sum of series 1+x+ x^2 + x^3+. . . +x^n
Code:
#include<stdio.h>
int main()
{
int x,n,t;
long sum=1;
printf("Enter the value of 'x': ");
scanf("%d",&x);
printf("\nEnter the value of 'n': ");
scanf("%d",&n);
t=x;
while(n>0)
{
sum=sum+t;
t=t*x;
n--;
}
printf("Sum of the series=%ld",sum);
}
Output:
Comments
Post a Comment