Programming Languages
Welcome to coding world
C Program to find the Sum of First n Natural numbers
Program to find sum of natural numbers using for loop
The user enters the value of n and the program calculate the
sum of first n natural numbers using for loop.
int main()
{
int n, count, sum
= 0;
printf("Enter
the value of n(positive integer): ");
scanf("%d",&n);
for(count=1; count
<= n; count++)
{
sum = sum +
count;
}
printf("Sum
of first %d natural numbers is: %d",n, sum);
return 0;
}
Output:
Enter the value of n(positive integer): 6
Sum of first 6 natural numbers is: 21