Computer Science Canada Putting a fraction into lowest terms |
Author: | Brutus [ Mon Jan 17, 2005 12:30 pm ] | ||
Post subject: | Putting a fraction into lowest terms | ||
Hey everyone, I'm new here so I'm not really sure how to post, but here goes. I am making a program that is supposed to calculate slpoe of a line segment. I can get the slope, but the problem is getting it into lowest terms. Any one know how I would achieve this? here is my program so far:
thanks in advance to whoever helps me |
Author: | Tony [ Mon Jan 17, 2005 1:27 pm ] |
Post subject: | |
to get a fraction in its lowest term, you find the factors of both nominator and denominator and divide them both by their common factors. |
Author: | Bacchus [ Mon Jan 17, 2005 3:34 pm ] | ||
Post subject: | |||
i sugest using mod to see the largest common denometer
|
Author: | wtd [ Mon Jan 17, 2005 4:54 pm ] |
Post subject: | |
Indentation is a good thing. ![]() |
Author: | AsianSensation [ Mon Jan 17, 2005 6:34 pm ] |
Post subject: | |
check up on Euclid's Algorithm. It's a very good way to find the GCD between two numbers and there are surprisingly quite alot of computer programming code out there regarding Euclid's Algorithm. |
Author: | Bacchus [ Mon Jan 17, 2005 9:55 pm ] |
Post subject: | |
wtd wrote: Indentation is a good thing. ya i kno but i didnt wrote it in turing and im lazy ![]() ![]() |
Author: | [Gandalf] [ Tue Jan 18, 2005 9:00 pm ] | ||||
Post subject: | |||||
Here's a quick tip on making your program more 'efficient'.
turns into
If anything, I would use the mod function - its probably more simple than some Eulcid's Algorithm ( ![]() |
Author: | AsianSensation [ Tue Jan 18, 2005 9:37 pm ] |
Post subject: | |
Euclid's Algorithm is an algorithm, that is to say, a set of instructions that you can follow and produce some result, that could be used over and over again until the desired answer is found. Mod in turing is a function, and it only returns only 1 value. They are not the samething. Besides, Euclid's algorithm, when typed into CS code, will need the mod function. As the math logic behind it even calls for the use of mod. |
Author: | Brutus [ Wed Jan 19, 2005 12:24 pm ] | ||
Post subject: | |||
Ok, thanks very much to all that posted. Bacchus, I tryed to use your idea, but i had to add the abs thing due to negative number. So here's what I have now.
Problem is now, that it won't run with the "i" and decreasing things. Any idea why? |
Author: | scottyrush13 [ Wed Jan 19, 2005 12:32 pm ] |
Post subject: | |
i think the other i's inside the for statement need to be in brackets |
Author: | Bacchus [ Wed Jan 19, 2005 3:44 pm ] |
Post subject: | |
no but the decreasing part has to come b4 the i ex) for decreasing i:5..1 |
Author: | Brutus [ Thu Jan 20, 2005 12:03 pm ] |
Post subject: | |
Thanks scotty and Bacchus. Hahaha, ya, the decreasing comes before the "i". Also, the "/" had to be changed to div. I hate it when the hardest answer to find is the simple one.... Anyways, thanks again. |
Author: | phuong [ Tue May 31, 2005 11:24 am ] |
Post subject: | |
if you're still interested... (don't think so but anyway) here's a program that CAN reduce fractions. check it out. here's the datafile for it too. |
Author: | [Gandalf] [ Wed Jun 01, 2005 10:10 am ] |
Post subject: | |
Well, I don't know - this was quite a while ago. I would just post something in the source code section - a new topic. Also, when you submit something, include all the files neccessary. |