Write a program to calculate and display sum of the following series using for loop x+x2+x3+………xn
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n,x;
int sum=0;
cout<<"Enter n: ";
cin>>n;
cout<<"Enter x: ";
cin>>x;
for(int i=1;i<=n;i++){
sum+=pow(x*1.0,i);
}
cout<<"Sum = "<<sum<<"\n";
cin>>n;
}
Comments
Leave a comment