Here is source code of the C program to calculate the sum of first N natural numbers. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to find the sum of 'N' natural numbers
int i, num, sum = 0;
printf("Enter an integer number \n");
scanf ("%d", &num);
for (i = 1; i <= num; i++)
sum = sum + i;
printf ("Sum of first %d natural numbers = %d\n", num, sum);
$ cc pgm3.c $ a.out Enter an integer number 1300 Sum of first 1300 natural numbers = 845650 $ a.out Enter an integer number 15 Sum of first 15 natural numbers = 120
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms