Q:

C Program to find out the sum of an A.P. series

0

C Program to find out the sum of an A.P. series.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#include <math.h>

void main(){

    int n1,df,n2,i,ln;
    int s1=0;

     printf("\n\n  Find out the sum of A.P. series :\n ");
     printf("----------------------------------------\n");


    printf("Input  the starting number of the A.P. series: ");
    scanf("%d",&n1);

    printf("Input the number of items for  the A.P. series: ");
    scanf("%d",&n2);

    printf("Input  the common difference of A.P. series: ");
    scanf("%d",&df);

    s1 = ( n2 * ( 2 * n1 + ( n2 -1 ) * df ) )/ 2;
    ln = n1 + (n2-1) * df;
    printf("\nThe Sum of the  A.P. series are : \n");

    for(i=n1;i<=ln; i= i + df ){
         if (i != ln)
             printf("%d + ",i);
         else
             printf("%d = %d \n\n",i,s1);
    }

} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now