Find the sum of all natural numbers between 1 to n with C.
#include <stdio.h>
int main()
{
int i, N, sum = 0;
printf("Enter Last Number N : ");
scanf("%d", &N);
for (i = 1; i <= N; i++)
{
sum += i;
}
printf("Sum %d natural numbers = %d", N, sum);
return 0;
}
Output:-
Enter Last Number N : 10
Sum 10 natural numbers = 55
0 Comments