WAP in C program to find out the sum of series 1 + 2 +3+4+ …. + n.

Here is the program to calculate the Sum of the Series 1+2+3 +.... n

#include<stdio.h>
int main()
{
 int j,m;
 int s=0;
 printf("Enter the maximum value of series , m: ");
 scanf("%d",&m);
 s = (m * (m + 1)) / 2;
 printf("Sum of the series is : ");
 for(j=1;j<=n;j++)
   {
    if (j!=n)
      printf("%d + ",j);
    else
      printf("%d = %d ",j,s);
   }
  return 0;
}

Post a Comment

0 Comments