+ 1
Write a program to find sum of the series. S= 1+x+x^2+....+x^n.
3 Answers
+ 9
int x, n;
cin >> x >> n;
cout << ((pow(x, n + 1) - 1) / (x - 1));
+ 3
here is a function :
... headed files void main etc.
cin>>x;
cin>>n;
int I;
int sum = 0;
for(I=0;I<=n;I++) {
sum+=pow(x,I);
}
cout<<sum;
0
// math header file included
int x,n;
cin>>x>>n;
// Using sum of n terms of a GP
cout<<'Sum of series: '<<x*(pow(x,n)-1) / x-1;