What is sum of series program?


The n-th partial sum of a series is the sum of the first n terms. The sequence of partial sums of a series sometimes tends to a real limit. If this happens, we say that this limit is the sum of the series. If not, we say that the series has no sum.

This series  is 1 +2 +3 +...+n

//Write a C program to calculate sum of series.

Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
    int i,N,sum;
   
    /*read value of N*/
    printf("Enter the value of N: ");
    scanf("%d",&N);
   
    /*set sum by 0*/
    sum=0;
   
    /*calculate sum of the series*/
 
    for(i=1;i<=N;i++)
   {
        sum= sum+ i;
    printf(" +%d",i);
   }
    /*print the sum*/

    printf("\n Sum of the series is: %d\n",sum);
   
    return 0;
}

Output:
Enter the value of N: 5
 +1 +2 +3 +4 +5

 Sum of the series is: 15

0 comments:

Post a Comment