Write a program in C to print the summation of the series 1 2 3 4 …. N, where N will be given through keyboard.

Write a program in C to print the summation of the series 1 2 3 4 …. N, where N will be given through keyboard.

Write a program in C to print the summation of the series 1 2 3 4 …. N, where N will be given through keyboard.

/*
Author : Sabya Roy
*/

 

#include<stdio.h>
#include<conio.h>
main ()
{
          int n, i, summation=0;                  //variable for N series (n)
          printf(“Enter the value of n : “);  //Show a dialog to input N
          scanf(“%d”, &n);                             //input the value of N
          for (i=1; i<=n; i++)                        //use of “for loop”
          {
                    summation=summation+i;
                    if(i==1)                                          //A condition
                    {
                              printf(“Series = %d,”,i);   //Show series from 1
                    }
                    else
                    printf(“%3d,”, i);                          //Show the full series
          }
          printf(“\nSummation of series : %d”, summation);
          getch();
}

———————————————————————————————————————————————————-




Output : 

Enter the value of n : 10
Series : 1,  2,  3,  4,  5,  6,  7,   8,  9,  10
Summation of series : 55

———————————————————————————————————————————————————-

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *