Code :
#include <stdio.h>
int main()
{
int n;
int sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
sum=sum+i;
}
printf("Sum of first n natural number:%d",sum);
return 0;
}
Sample Input and Output:
Enter the value of n:5
Sum of first n natural number:15
If you any have doubt,suggestion regarding this post or website then feel free to share with us.
If you have learned something new from this post then share this post with your family and
friends.
friends.
Tags:
n natural numbers in c
natural numbers in c program
print natural numbers in c
sum of natural numbers in c