Here is a C++ program to generate Geometric Progression(GP) series
SOURCE CODE OUTPUT
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long r,n,a1,an;
cout<<"Enter first term ";
cin>>a1;
cout<<"Enter common ratio ";
cin>>r;
cout<<"Enter number of terms";
cin>>n;
cout<<"Geometric series : ";
for(int y=0;y<=n;y++)
{
an=a1*pow(r,y);
cout<<an<<" ";
}
return 0;
}
#include<math.h>
using namespace std;
int main()
{
long r,n,a1,an;
cout<<"Enter first term ";
cin>>a1;
cout<<"Enter common ratio ";
cin>>r;
cout<<"Enter number of terms";
cin>>n;
cout<<"Geometric series : ";
for(int y=0;y<=n;y++)
{
an=a1*pow(r,y);
cout<<an<<" ";
}
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment