#include <iostream>
using namespace std;
void main()
{
int n1,df,n2,i,ln;
int s1=0;
cout<<" Find out the sum of A.P. series :\n ";
cout<<"Input the starting number of the A.P. series: ";
cin>>n1;
cout<<"Input the number of items for the A.P. series: ";
cin>>n2;
cout<<"Input the common difference of A.P. series: ";
cin>>df;
s1 = ( n2 * ( 2 * n1 + ( n2 -1 ) * df ) )/ 2;
ln = n1 + (n2-1) * df;
cout<<"\nThe Sum of the A.P. series are : \n";
for(i=n1;i<=ln; i= i + df )
{
if (i != ln)
cout<<" + "<<i;
else
cout<<i<<" = "<<s1<<endl;
}
system ("pause");
}
Test Data :
Input the starting number of the A.P. series: 1
Input the number of items for the A.P. series: 10
Input the common difference of A.P. series: 4
Expected Output :
The Sum of the A.P. series are :
1 + 5 + 9 + 13 + 17 + 21 + 25 + 29 + 33 + 37 = 190
using namespace std;
void main()
{
int n1,df,n2,i,ln;
int s1=0;
cout<<" Find out the sum of A.P. series :\n ";
cout<<"Input the starting number of the A.P. series: ";
cin>>n1;
cout<<"Input the number of items for the A.P. series: ";
cin>>n2;
cout<<"Input the common difference of A.P. series: ";
cin>>df;
s1 = ( n2 * ( 2 * n1 + ( n2 -1 ) * df ) )/ 2;
ln = n1 + (n2-1) * df;
cout<<"\nThe Sum of the A.P. series are : \n";
for(i=n1;i<=ln; i= i + df )
{
if (i != ln)
cout<<" + "<<i;
else
cout<<i<<" = "<<s1<<endl;
}
system ("pause");
}
Test Data :
Input the starting number of the A.P. series: 1
Input the number of items for the A.P. series: 10
Input the common difference of A.P. series: 4
Expected Output :
The Sum of the A.P. series are :
1 + 5 + 9 + 13 + 17 + 21 + 25 + 29 + 33 + 37 = 190
Write a c++ program to find out the sum of in A.P. series. .
Reviewed by Unknown
on
June 11, 2017
Rating:
No comments: