This is my solution for the problem ALCHEMY on SPOJ :
#include <stdio.h> int main (void) { float a = 1000, b = 37; unsigned long int x, y; float z = a / b; for (x,y; x != -1, y != -1;) { scanf ("%lu %lu", &x, &y); if ((float)x / (float)y == z && x != -1 && y != -1) printf ("Y\n"); else if (x / y != z && x != -1 && y != -1) printf ("N\n"); else if ( y == 0) return 1; else if (x == -1 && y == -1) return 876; } return 0; }
Even if I enter x
and y
as 1000
and 37
respectively, the first if
statement is evaluated as false and it prints N
instead of Y
. Is it even possible to solve this problem the way I m trying and using float
? What am I doing wrong?
Please try to run it once.