#include<stdio.h>
#include<conio.h>
main()
{
int i,n,d,a,tn,sum=0;
clrscr();
printf("\n enter the first term of the A.P.");
scanf("\n %d",&a);
printf("\n enter the difference of A.P.");
scanf("\n %d",&d);
printf("\n enter the total term in A.P.");
scanf("\n %d",&n);
sum=(n*(2*a+(n-1)*d))/2;
tn=a+(n-1)*d;
printf("\n sum of series =");
for(i=a;i<=tn;i=i+d);
{
if(i!=tn)
{
printf("%d+",i);
}
else
{
printf("\n %d=%d",i,sum);
}
}
return (0);
}
output:-
first term of A.P. is a=3
difference of A.P.is d=5
total term of A.P. is n=5
sum of the series= 3+8+13+18+23=65