Sum of odd numbers in given range
C Program to find sum of odd 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 odd numbers in the range (%d-%d) = %d", low, high, sum);
getch();
}
Output
Enter lower limit: 5
Enter upper limit: 45
Sum of odd numbers in the range (5-45) = 525