Turbo C - Sum of ALL Numbers in the Given Range
Here is the Turbo C program for the sum of ALL Numbers given a range.
Source Code
#include <stdio.h>
void main()
{
int index, begno, endno, sum = 0;
printf("Program for sum of all numbers in the given range\n");
printf("Enter Beg. No.: ");
scanf("%d", &begno);
printf("Enter End. No.: ");
scanf("%d", &endno);
index = begno;
for(; index <= endno; index ++)
sum = sum + index;
printf("The sum of even numbers between %d and %d is: %d", begno, endno, sum);
}
Output
Program for sum of all numbers in the given range
Enter Beg. No.: 1
Enter End. No.: 100
The sum of even numbers between 1 and 100 is: 5050
|