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
- Take input from user.
- Take one variable and initialize it by 0.
- Run the for loop from one to input number.
- Execute the statement for summation inside the for loop.
- Finally print the result.
Sum of n number
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
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.
Reviewed by Deepak kumar soni
on
December 30, 2018
Rating:
No comments: