Find the sum of all even numbers between a to b with C.
#include <stdio.h>
int main()
{
int i, first, last, sum = 0;
printf("Enter first Number: ");
scanf("%d", &first);
printf("Enter last Number: ");
scanf("%d", &last);
for (i = first; i <= last; i ++)
{
if (i % 2 == 0)
{
sum += i;
}
}
printf("Sum of all even number between %d to %d = %d", first, last, sum);
return 0;
}
Output:-
Enter first Number : 5
Enter last Number : 20
Sum of all even number between 5 to 20 = 104
0 Comments