Write a C++ program to calculate the sum of finite GP series and display the result on screen.

Program Code:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float x,r,i,m;
int n;
float sum=0;
cout<<"Enter the first number of the GP series : ";
cin>>x;
cout<<endl;
cout<<"Enter the number of terms in the GP series : ";
cin>>n;
cout<<endl;
cout<<"Enter the common ratio of the GP series : ";
cin>>r;
cout<<endl;
sum = (x * ( 1 - pow( r, n+1 ) ) ) / (1 - r);
m = x * pow ( r, n-1 );
cout<<"Sum of all the numbers of the GP series is : ";
cout<<sum;
return 0;



The program output is tested on www.jdoodle.com
Output:
Enter the first number of the GP series : 1
Enter the number of terms in the GP series : 10
Enter the common ratio of the GP series : 2
Sum of all the numbers of the GP series is : 2047


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: