Hello , I want to ask why I am not receiving the same result using either the if
with break
inside the while loop ,either the while( x!=X && y!= Y )
.
#include <stdio.h>
#include <stdlib.h>
int sol( int X, int Y )
{
int x = 0, y = 1,i = 0;
while ( x!= X && y!= Y )
//while (1)
{
if ( i % 2 != 0 ) x += 1;
if ( i % 2 == 0 ) y += 1;
i++;
printf( "x = %d\t y = %d\t i = %d\n",x,y,i );
//if ( x == X && y == Y ) break;
}
return i;
}
int main( int argc, char ** argv )
{
printf( "sol = %d\n",sol(2,3) );
return 0;
}