Saturday, 17 November 2012

Sum of Series

write a program that will calculate the sum of series:   x+x2+x3+...............+xn
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n_value,x_value,sum=0;
cout << "Enter The value of X: ";
cin >>x_value;
cout << "Enter The value of N: ";
cin >>n_value;
for (int i=1;i<=n_value;i++)
{
sum=sum + pow(x_value,i);
}
cout << "Sum is: " << sum <<endl;
return 0;
}

No comments:

Post a Comment