ProAnswers.org

Write a C program to find out the Sum of N Numbers Using While Loop?

#include

#include 

void main() 

{ 

int i=1,sum=0; 

clrscr(); 

printf(“enter the value of n

”);

scanf(“%d”,&n); 

while(i<=n) 

{ 

sum=sum+i; 

i++; 

} 

printf(“sum=%d”,sum); 

getch(); 

} 

Output: 

enter the value of n 

5 

sum=15