Input and Output Format:
Input consists of a number which corresponds to the bill number. bill number is a 3-digit number and all the 3 digits in the number are even.
Output consists of a string that is either 'yes' or 'no'. Output is yes when the customer receives the prize and is no otherwise.
Samples:
Input Output
565 no
620 yes
66 no # Not a 3-digit number (implicit leading zeros not allowed)
002 yes # 3-digit number
I have solved the problem by getting single digit with "number" mod 10 and then checking if "digit" mod 2 is 0 or not......
But in case if I give input "002", it prints "no" instead I want it should be "yes".
Code — copied and formatted from comment:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
int num, t, flag, count = 0;
while (num)
{
t = num % 10;
num = num / 10;
if (t % 2 == 0)
{
flag = 1;
}
else
{
flag = 0;
}
count++;
}
if (flag == 1 && count == 3)
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}