cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How to store a fraction in reduce form
How to store a fraction in reduce form
Oct 23, 2009 at 3:46pm UTC
Progesco
(23)
How can I store a fraction in reduce form? For example, I input fraction 2/4, and print out 1/2
Oct 23, 2009 at 4:14pm UTC
hamsterman
(4538)
You have to find the greatest common divisor of the two numbers and divide each number by it.
see
http://en.wikipedia.org/wiki/Greatest_common_divisor
and
http://en.wikipedia.org/wiki/Binary_GCD_algorithm
though that algorithm seems a little complicated...
Last edited on
Oct 23, 2009 at 4:17pm UTC
Oct 23, 2009 at 4:19pm UTC
screw
(145)
My first idea was the string with which you can process. Than I used the google :)
Somebody wanted to write a class which is related your task:
http://www.daniweb.com/forums/thread38955.html#
Topic archived. No new replies allowed.