Sum of even numbers in given range
C Program to find sum of even numbers in given range
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i, low, high, sum=0;
printf("Enter lower limit: ");
scanf("%d", &low);
printf("Enter upper limit: ");
scanf("%d", &high);
for(i=low; i<=high; i++)
{
if(i % 2 == 0)
{
sum += i;
}
}
printf("Sum of Even numbers in the range (%d-%d) = %d", low, high, sum);
getch();
}
Output
Enter lower limit: 5
Enter upper limit: 12
Sum of Even numbers in the range (5-12) = 36