C Program to Find the Sum of A.P Series

C Program to Find the Sum of A.P Series

 #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;

    }

Share this post


Comments (0)

  • Be first to comment

Leave a comment

or to Comment

Contact Us

  • Address: # 650 Narsi Village Sector 32 Urban Estate Karnal-132001 Haryana, India

  • Phone:(+91) 97289-77666   Email: codethor84@gmail.com


Follow Us