Find Sum Of Arithmetic Progression (A.P) | user given A.P | C-Program
Sum of Arithmetic progression user given number:
Tips:
1.Take variables.
2.Use for loop.
Code:
#include<stdio.h>
void main()
{
int a,d,n,i,j,k,l=0,m;
printf("Enter lst no. of A.P series: \n");
scanf("%d",&a);
printf("Enter the common difference: \n");
scanf("%d",&d);
printf("Enter the Term value:\n");
scanf("%d",&n);
for(m=1;m<=n;m++)
{
k=(m-1)*d+a;
if(m!=n)
printf("%d+",k);
else
printf("%d=",k);
l=l+(m-1)*d+a;
}
printf("%d",l);
getch();
}
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)