sum of n number(while loop)
Sum of n number using while loop
C program to find sum of n number enter from user using while loop.
Method followed in program
- Take the input from the user to find sum of number.
- Declared variable and initialize it with variable 0.
- Apply the condition for while loop.
- Execute the statement inside program to find sum.
- Finally print the sum of enter number.
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);
i=1;
while(i<=num)
{
sum=sum+i;
}
printf("sum is %d",sum);
getch();
}
sum of n number(while loop)
Reviewed by Deepak kumar soni
on
December 30, 2018
Rating:
No comments: