#include <stdio.h>
int evenDigits1(int num);
int main() {
int number;
printf("Enter a number: \n");
scanf("%d", &number);
printf("EvenDigits(): %d\n", evenDigits1(number));
return 0;
}
int evenDigits1(int num) {
int x, result, i = 1;
float evenNum = 0;
while (num != 0) {
x = num % 10;
if (x % 2 == 0) {
evenNum += x;
evenNum /= 10;
i *= 10;
}
num /= 10;
}
result = evenNum * i;
if (result == 0) {
return -1;
} else {
return result;
}
}
Why is it when I enter 4488
or 1144889
, it will display 4487
instead of 4488
? For other number such as 44488
or 123456
, it will show correctly (44488
and 246
).
How do I display 4488
as 4488
instead of 4487
?
Thanks for your help.