Write a program to find the sum of n natural numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,i;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum=sum+i;
printf("Sum=%d",sum);
getch();
}
Output:
Enter the number: 10
Sum=55
No comments: