Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sum of G.P

C++ Program to calculate sum of finite G.P. This program calculates the sum of the a finite G.P. and prints the result on the compiler screen. The first term 'a', number of terms 'n' and the common ratio 'r' are input by the user. Sum of an G.P. is calculated by the formula : sum=(a*(1-pow(r,n+1)))/(1-r) , nth term by : nth=a*pow(r,n-1) . For loop is used to print the whole series upto n
and the sum is printed on compiler screen

Source Code:-

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
 float a,r,i,nth;
 int n;
 float sum=0;
 clrscr();
 cout<<"Program to calculate sum of G.P. by-Tarun Rawat\n";
 cout<<"Enter the first number of series : ";
 cin>>a;
 cout<<"Enter the number of terms in series : ";
 cin>>n;
 cout<<"Enter the common ratio of series : ";
 cin>>r;
 sum=(a*(1-pow(r,n+1)))/(1-r);
 nth=a*pow(r,n-1);
 cout<<"n'th term of G.P. : "<<nth;
 cout<<"\nSum of the G.P. : "<<sum;
 getch();
}

No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)