Interview Question
Country: United States
This looks right. Notice that he is looking at repeating remainder.
So for example of 1/7
Remainder is 1.
Mutiply by 10.
Now 7 goes 1 time in 10, and remainder is 3.
0.1
Multiply 3 by 10 = 30
7 goes 4 times and remainder is 2.
0.14
2*10 = 7*2 + 6
0.142
6*10 = 7*8 + 4
0.1428
4*10 = 7*5 + 5
0.14285
5*10 = 7*7 + 1
0.142857
remainder 1 has come again, so we are going to repeat.
Thus 1/7 = 0.(142857)
Divide until you either have no remainder or the remainder is one you've seen before. Then print and insert "(" at the place where you saw the remainder before and ")" at the end, if a repeating fraction
- Anonymous July 04, 2014