Help required with Ciel and A - B problem...

Here’s the C code for the problem “Ciel and A - B”. Though it works awesome for sample input and a few other corner cases I tried, it doesn’t work and gives me a “wrong Answer” error.

Can anyone please help me with this:

#include <stdio.h>
#include <math.h>

int main(void) {
   int A, B;
scanf ("%d %d", &A, &B);
int num = A - B;
if ( (int) log10 (num) + 1 == (int) log10(num - 1) + 1 && (num - 1) % 10 != 0)
{
    printf ("%d\n", num - 1);
    return 0;
}
else
{
    printf ("%d\n", num + 1);
    return 0;
}

}

Check for this case

100 10

Answer should either be

9* or *0, *={1 to 9}

Your code outputs 89.

1 Like

Ah! Didn’t see that :stuck_out_tongue: thanks for letting me know…

//