Can someone explain this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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; }

1st Jun 2022, 8:38 AM
Sofija
Sofija - avatar
5 Answers
+ 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 ...
1st Jun 2022, 8:58 AM
Ipang
+ 2
<a>, <b>, <x> and <y> are all uninitialized, you may expect them to contain garbage values. What are you trying to do though?
1st Jun 2022, 8:51 AM
Ipang
+ 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.
2nd Jun 2022, 6:04 PM
Axel Gottwald
Axel Gottwald - avatar
+ 1
I know, I saw the error that compiler reports, so the exam itself has errors. Thank you for clarifying.
1st Jun 2022, 9:03 AM
Sofija
Sofija - avatar
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
1st Jun 2022, 8:54 AM
Sofija
Sofija - avatar