+ 2

Can anyone help me?

Given two natural numbers M and N - the numerator and denominator of the fraction M / N. It is required to reduce the fraction as much as possible.

6th Nov 2020, 8:46 AM
Zaur
1 Odpowiedź
+ 3
I guess this should work: int min = Math.min(M, N); for (int i = 2; i < min; i++) { if((M%i == 0) && (N%i == 0)) { M /= i; N /= i; i--; } } System.out.print(M + "/" + N);
14th Dec 2020, 10:55 AM
Lukáš Vladař