programming-examples/c/Functions/C Program to Find the Sum of First N Natural Numbers.c
2019-11-15 12:59:38 +01:00

16 lines
343 B
C

/*
* C program to find the sum of 'N' natural numbers
*/
#include <stdio.h>
void main()
{
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);
}