Saturday, 13 December 2014

C PROGRAM FOR SUM OF N NATURAL NUMBERS

Write a program to find the sum of N natural numbers.

#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,N,sum=0;
clrscr();
printf("sum of how many natural numbers do you want?");
scanf("%d",&N);
while(i<=N)
{
sum=sum+i;
i++;
}
printf("The sum of N natural numbers is:%d",sum);
getch();
return(0);
}

OUTPUT:
Sum of how many natural numbers do you want? 2

The sum of N natural number is: 3

No comments:

Post a Comment