Cody

Problem 918. Find the repeating decimal pattern!

Write a function that takes one double input value and returns only the repeating decimal, if any, as a string. Only decimals for which all digits are part of the repeating pattern will be counted. (See the 3rd example below.) Inputs will be in the range [0 1].

If no repeating decimal is found, the function should return an empty string. Of course the repeating decimal may break down in the last bit due to floating point arithmetic, but we will ignore that.

Examples:

T = repeatingdec(7/11)  % Returns T = '63'
T = repeatingdec(1/3)   % Returns T = '3'
T = repeatingdec(5/6)    % Returns T = ''
T = repeatingdec(0)      % Returns T = '0'

Solution Stats

21.84% Correct | 78.16% Incorrect
Last solution submitted on Mar 11, 2016

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more