algorithm - Write a program that takes as input numerators and denominators of fractions and determines their repeating cycles -


for example :

76/25 = 3.04(0) 1 = number of digits in repeating cycle

5/43 = 0.(116279069767441860465) 21 = number of digits in repeating cycle

1/397 = 0.(00251889168765743073047858942065491183879093198992...) 99 = number of digits in repeating cycle

this might ugly solution, should work:

  • simplify fraction using greatest common divisor (gcd) - optional , used simplify calculations.
  • do paper-and-pencil division. division encounters repeating remainder can break off, since after point numbers repeat. example:

    5 / 27 = 0.185... 50 <------------------------------| -27 -> (1) | 230 | -216 -> (8) | 140 | -135 -> (5) | 50 <-------- same remainer here, can break off -27 -> (1)

sorry ugly ascii-"art".


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -