Thursday, 16 November 2017

C Program to Find the Sum of A.P Series


Code:

#include   stdio.h
#include   math.h

int main()
{
     int a, d, n, i, tn;
     int sum = 0;

     printf("Enter the first term value of the A.P. series: ");
     scanf("%d", &a);
     printf("Enter the total numbers in the A.P. series: ");
     scanf("%d", &n);
     printf("Enter the common difference of A.P. series: ");
     scanf("%d", &d);
     sum = (n * (2 * a + (n - 1)* d ))/ 2;
     tn = a + (n - 1) * d;
     printf("Sum of the A.P series is: ");
     for (i = a; i <= tn; i = i + d )
     {
          if (i != tn)
               printf("%d + ", i);
          else
               printf("%d = %d ", i, sum);
     }
     return 0;
}


Output:

Enter the first term value of the A.P. series: 1
Enter the total numbers in the A.P. series: 5
Enter the common difference of A.P. series: 2
Sum of the A.P series is: 1 + 3 + 5 + 7 + 9 = 25


More C Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...