โ Back to Structs
Question 348
Simplify a Fraction
Simplify a Fraction
Astruct Fractionholdsnum = 6andden = 8. Reduce it to lowest terms by dividing both fields by their greatest common divisor (GCD), then print the result asnum/den: 3/4 The GCD of 6 and 8 is 2, giving3/4. You will need to compute the GCD yourself (the Euclidean algorithm works well). There is no trailing newline.
Expected Output:
3/4
Topics:
Structs
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.