Sunday, 14 February 2016

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.

Where X and Y are variables whose value is entered by user 


#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int x,n,power;
int sol=0;
cout<<"Enter the values of x and n:";
cin>>x>>n;
for(int i=1;i<=n;i++)
{
    sol=sol+pow(x,i);
   
}
cout<<"Sum="<<sol<<endl;
system("pause");
return 0;
}

---------------------------------------------------------------------------
Output:




For help and questions leave comments....


No comments:

Post a Comment