Hello , I have qusetion about how to get the fraction reduced form like ( 2/4 = 1/2) and so on in C++ programming language
This is a discussion on how to get a reduced form within the C++ Programming forums, part of the General Programming Boards category; Hello , I have qusetion about how to get the fraction reduced form like ( 2/4 = 1/2) and so ...
Hello , I have qusetion about how to get the fraction reduced form like ( 2/4 = 1/2) and so on in C++ programming language
Last edited by silent_eyes; 02-25-2005 at 11:20 AM.
The same way you would if you were doing it on paper.
1) Find the greatest common divisor of the numerator and denominator.
2) Divide both the numerator and the denominator by the greatest common divisor.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
C++ doesn’t do fractions (natively). Like a calculator, it can handle integers and floating-point numbers.
You will have to write your own code to:
1. Get the user’s input, and separate the numerator and denominator.
2. Save the numerator and denominator as two different variables.
3. Manipulate the variables as desired (reduce fraction).
4. Display the new numerator and denominator so it looks like a fraction.
Last edited by DougDbug; 02-25-2005 at 12:43 PM.
Thanks )