This c program prompts the user to enter the value of n, then it calculates the sum of the first N natural numbers using a for
loop, and finally, it prints the result.
You can run this program, enter a value for N, and it will display the sum of the first N natural numbers.
Program :
#include<stdio.h>
#include<conio.h>
main()
{
int n,sum,i;
i=1;
sum=0;
printf(“Enter How many numbers do you want to add up to : “);
scanf(“%d”,&n);
while(i<=n)
{
sum=sum+i;
i=i+1;
}
printf(“%d is the Sum of first %d numbers.”,sum,n);
}
Output :
