Monday, June 13, 2016

C program to find the sum of first 100 natural numbers.

#include<stdio.h>
int main()
{
int i, sum, temp;

sum=0; 
temp=1;

for( i=0; i<100; i++ )
{
sum = sum + temp;
temp = temp + 1;
}

printf("%d",sum);
 return 0;
}

Output of the program:

5050

No comments:

Post a Comment