C program to find sum of series 1+x+x^2+……+x^n

C program to find sum of series 1+x+x^2+......+x^n

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 int i,n;
float x,sum=0;
clrscr(); //to clear the screen
printf(“1+x+x^2+……+x^n”);
printf(“nnEnter the value of x and n:”);
scanf(“%f%d”,&x,&n);

for(i=1;i<=n;++i)
sum+=pow(x,i);
 sum++;
printf(“nSum=%f”,sum);
getch(); //to stop the screen
}

5 thoughts on “C program to find sum of series 1+x+x^2+……+x^n

  1. Archi Goyal

    Why did you used x as an float?
    since i used it as int and my result changed ony for x=5 and n=2 as 30 instead of 31!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *