***************** Calculate the sum of all the even
numbers between the range the user inputs *************
This is what I have so far... but something is wrong and I can't figure it out... I keep getting 0 (zero) when I run the program. Please Help!
#include<stdio.h>
int main()
{
int display, min, max;
int sum=0;
int counter1, counter2;
printf("Enter minimum value: ");
scanf("%d", &min);
printf("Enter maximum value: ");
scanf("%d", &max);
counter1=min%2;
counter2=min+1;
if (counter1>0)
{
for (display=counter2; display<=max; display=display+2)
sum=sum+display;
}
if (counter1=0)
{
for (display=min; display<=max; display=display+2)
sum=sum+display;
}
printf("%d", sum);
}
Bookmarks