Aim of the program:
to calculate the sum of first 100 numbers
Algorithm:
Source code:
#include <stdio.h>
main()
{
int i, sum=0;
printf("\n\tSum of first 100 positive numbers\n");
for(i=0; i<=100; i++)
sum = sum + i;
printf("\nSum = %d", sum);
getch();
}
Sample output:
to calculate the sum of first 100 numbers
Algorithm:
step 1: initialise i=0, sum=0
step 2: repeat loop until i>100
step 2.1: determine sum <- sum + i
step 2.2: calculate i <- i + 1
step 3: print sum
Source code:
#include <stdio.h>
main()
{
int i, sum=0;
printf("\n\tSum of first 100 positive numbers\n");
for(i=0; i<=100; i++)
sum = sum + i;
printf("\nSum = %d", sum);
getch();
}
Sample output: