Write a program sum of first n natural numbers in C.

#include<stdio.h>

void main ()
{
int i,n ,sum= 0;
scanf("%d",&n);
printf("The first 7 natural is:",n);
for(int i=1;i<=7;i++)
{ printf("%d ",i);
sum=sum+i;
}
printf("\nThe Sum of Natural Number upto 7 terms : %d",sum);

return 0;
}

Write a program in C to display the first 10 natural numbers.

1 thought on “Write a program sum of first n natural numbers in C.”

Leave a Comment