C Program to print the sum of n even numbers within range using while
Program
#include<stdio.h>
void main()
{
int i;
int start_range, end_range;
int sum = 0;
printf("Enter the starting range:\t");
scanf("%d", &start_range);
printf("Enter the ending range:\t");
scanf("%d", &end_range);
printf("Sum of even numbers in the given range is: ");
i = start_range;
while (i <= end_range)
{
if (i % 2 == 0)
sum = sum + i;
i++;
}
printf("%d", sum);
}
Output
$ gcc sum-of-n-even-numbers-within-range-using-while.c
$ ./a.out
Enter the starting range: 3
Enter the ending range: 10
Sum of even numbers in the given range is: 28