![]() |
|
#1
|
|||
|
|||
Simplifying a fractionCan someone please help me write a piece of c++ code that will simplify a fraction, for example 4/16, the answer would be 1/4, on paper this is easy as sin, but as a begginer programmer im having trouble coding it. PLEASE HELP!
Dan |
|||
|
#2
|
||||
|
||||
Re: simplifying a fraction1. Find the greatest common divisor of the numerator and denominator.
2. Divide both the numerator and denominator by the gcd. CPP / C++ / C Code:
__________________
www.blake-foster.com |
|
#3
|
|||
|
|||
Re: simplifying a fractionThis is pretty simple. You have two integers....a numerator and a denominator. The goal is to divide both of these numbers by the largest number that will still give a whole number. So, you will need a function that will give you that number to divide by:
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Simplifying a fractionthanks guys i really appreciate that... the code that you provided blake didnt work for me cause i was to use structures... but it definitely helped me.. and it work great with individual values.. but this is what i was after
CPP / C++ / C Code:
you guys are the best thanks again.... Daniel and sorry i cant seem to get the tags to show my code properly.. what i am doing wrong??? Last edited by LuciWiz : 27-Jan-2009 at 13:55.
Reason: Corrected code tags
|
|
#5
|
||||
|
||||
Re: Simplifying a fractionQuote:
The [c] and [cpp] tags are not supposed to be used as an enumeration (just choose one). The preferred tag now is [cpp], which can be used for both C and C++ code, as in: [cpp] // your code [/cpp] __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#6
|
|||
|
|||
Re: Simplifying a fractionthanks Wiz
|
|
#7
|
|||
|
|||
Re: Simplifying a fractionQuote:
Did you test it with 6/8? How about 21/14? Regards, Dave |
|
#8
|
|||
|
|||
Re: Simplifying a fractionohhh shitt! your right Dave.. prof is not gona be happy..
I will repost a working version. thanks Dave Dan |
|
#9
|
|||
|
|||
Re: Simplifying a fractionoookk got it.. this one works great. Thanks again Dave... im getting better.
CPP / C++ / C Code:
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [C#] Method that recieves matrix values as a string | Max_Payne | .NET Forum | 1 | 17-Jun-2008 07:44 |
| Fraction program | SpudNuts | C++ Forum | 6 | 25-Sep-2006 04:50 |
| Defining a class | earachefl | C++ Forum | 8 | 04-May-2006 22:22 |
| fraction class program | fevershark | C++ Forum | 7 | 31-Jan-2006 12:12 |
| accessing a private member in a public member | small_ticket | C++ Forum | 2 | 16-Oct-2004 12:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The