Wednesday, 18 June 2014

C++ program to find nth term Arithmetic progression(AP) series and its sum



Here is a C++ program to find nth term Arithmetic progression(AP) series and its sum


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    long d,n,a1,an;
    float sum;
    cout<<"Enter first term ";
    cin>>a1;
    cout<<"Enter difference ";
    cin>>d;
    cout<<"Enter value of n ";
    cin>>n;
    an=a1+(n-1)*d;
    sum=n*(a1+an)/2.0;
    cout<<n<<"th term of A.P. is "<<an;
    cout<<endl<<"Sum ="<<sum<<endl;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment