Sum of n numbers.

Sum of n numbers


C program to find sum of n number enter from the user by using for loop concept.It will sum the number enter from the user.




Steps followed in program

  1. Take input from user.
  2. Take one variable and initialize it by 0.
  3. Run the for loop from one to input number.
  4. Execute the statement for summation inside the for loop.
  5. Finally print the result.

Sum of n number

#include<stdio.h>
#include<conio.h>
void main()
{
   clrscr();
   int num,sum=0,i;
   printf("Enter number\n");
   scanf("%d",&num);
   for(i=1;i<=num;i++)
   {
     sum=sum+i;
   }
  printf("Sum is %d",sum);
  getch();
}


Sum of n numbers. Sum of n numbers. Reviewed by Deepak kumar soni on December 30, 2018 Rating: 5

No comments:

Powered by Blogger.