Canadian Computing Competition: 2002 Stage 1, Junior #4, Senior #2
Many advanced calculators have a fraction feature that will simplify fractions for you.
You are to write a program that will accept for input a non-negative integer as a numerator and a positive integer as a denominator, and output the fraction in simplest form. That is, the fraction cannot be reduced any further, and the numerator will be less than the denominator. You can assume that all input numerators and denominators will produce valid fractions.
Sample Input 1
28
7
Sample Output 1
4
Sample Input 2
13
5
Sample Output 2
2 3/5
Sample Input 3
0
7
Sample Output 3
0
Sample Input 4
55
10
Sample Output 4
5 1/2
Comments
What's the format? I tried both a new line at the end and no new line at the end, neither worked :(
o i got it now, because i forgot to write kinds with only a number :(
Your code outputs an unnecessary space character when the result is a non-zero integer. For example, for the first sample, the output of your program is equivalent to
System.out.print("4 \n");
.Unless explicitly stated otherwise, you should assume that problems have input/output with each line being terminated by a
\n
character with no trailing whitespace.For those getting presentation error make sure to print a newline at the end
If the answer turns out to be 0 and a fraction, do we just need to print 0? I keep getting a wrong answer on the answers with 0 in them
If the answer is 0 1/2, don't print the 0