The sum of n natural numbers in C

 #include<stdio.h>

int main()

{

int i,sum=0,n;

printf("Enter the value of n");

scanf("%d", &n);

for(i=0; i<=n; i++){

     sum+=i;

}

printf("The sum of n natural numbers is %d", sum);

return 0;

}

Comments

Popular posts from this blog

Make a number game in C

Reverse printing in c

structure formate in c