Fraction Simplifier

This challenge consists of writing a program that asks the end-user to enter a fraction (numerator and denominator) and output the matching reduced fraction when the fraction can be reduced.

To see what this program should do in action you may want to try fractionsimplifier.com.

fraction_numerator_denominator

To simplify a fraction your program will need to find the greatest common divisor (aka greatest common factor) of the numerator and denominator that will have been entered by the end user. Then, your program will divide the numerator and denominator of the fraction by this number.

fraction

To find out if a number is a factor of the numerator you will need to check that the remainder of the numerator divided by this number is null (=0):

  • For instance 3 is a factor of 24 because 24 mod 3 = 0.
  • remainder_24

  • Whereas 5 is NOT a factor of 32 because 32 mod 5 = 2 != 0.
  • remainder32

Extra tip: A factor of a number is always lower or equal to this number.

Your Challenge:


Complete the code below to find the greatest common factor of both the numerator and denominator entered by the end-user and use it to output the simplified fraction.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4 / 5. Vote count: 5

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,