+ 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.
1 Resposta
+ 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);