40 C Program to Find the Sum of first 50 Natural Numbers using For Loop
Posted by Superadmin on December 23 2015 03:22:24
This C Program finds sum of first 50 natural numbers using for loop.
Here is source code of the C program to find the sum of first 50 natural numbers using for loop. 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 first 50 natural numbers
* using for loop
*/
#include <stdio.h>
void main()
{
int num, sum = 0;
for (num = 1; num <= 50; num++)
{
sum = sum + num;
}
printf("Sum = %4d\n", sum);
}
$ cc pgm73.c
$ a.out
Sum = 1275