- 1
Can someone explain this code?
#include <stdio.h> int main() { unsigned a,b,x,y,temp; x=a*b; while(b) temp=a%b,a=b,b=temp; y=b; x/=y; return 0; }
5 Respuestas
+ 4
I don't know where you got this from, but if you try to run this code you'll see warnings about uninitialized variables, which I think triggers the arithmetic error.
FYI, the code execution doesn't make it to the x /= y; line, it is terminated for a critical error ...
+ 2
<a>, <b>, <x> and <y> are all uninitialized, you may expect them to contain garbage values.
What are you trying to do though?
+ 2
One reason why x/=y could not be computed is that y must be 0 at the time of execution. y gets the value of b after the while loop which ends if b gets 0. I don't know if that's a good explanation but this should probably be a math error.
+ 1
I know, I saw the error that compiler reports, so the exam itself has errors. Thank you for clarifying.
0
This code is for exam, and the correct answer is "there is an error in the last line of code (x/=y)" - but I don't know what's problem in that line of code