Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Help me with Fraction Code
Closed Thread
Old 11-19-2005, 02:52 PM   #1 (permalink)
 
Wizard Techie

Join Date: Jun 2005

Posts: 3,346

Tyler1989

Default Help me with Fraction Code

Can someone please help me with the code for deducing a fraction. The user enters a numerator and a denominator through textboxes then click a buttion. The end result is a reduced fraction in a lable. Logically you can do this in your head but when you have to do it in Basic it must be done with loops and such I'm clueless.
__________________
<form action=\"http://www.srsyo.org/tfsearch.php\" method=\"get\">
<input type=\"text\" name=\"search\"> <input type=\"submit\" name=\"submit\" value=\"Search TF before you post!\"></form>
Vista Discussion | 64 Bit Discussion |Microsoft Homepage | Yo Linux | Paul Thurrott | Fire Fox | Thunder Bird | Image Shack | Photo Bucket | Put File | Anti-Spyware | MS Anti-Spyware | Trillian | Anti-Virus | On Line Virus Scan
Tyler1989 is offline  
Old 11-19-2005, 06:19 PM   #2 (permalink)
 
Ultra Techie

Join Date: Jul 2005

Posts: 530

TheHeadFL

Send a message via AIM to TheHeadFL
Default

You need to use a GCD (Greatest Common Divisor) algorithm.

The easiest one to code is the one that Euclid invented...

Say I want to do 84/18. I determine which one is larger, and divide 84 by 18 leaving remainder 12. Then I divide 18 by 12 leaving remainder 6. Then I divide 12 by 6 to get remainder 0, which means that 6 is the GCD. Therefore, the fraction may be reduced by a factor of 6/6.

I leave it to you to do this in BASIC.
__________________
Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache)
TheHeadFL is offline  
Old 11-20-2005, 12:38 PM   #3 (permalink)
 
True Techie

Join Date: Nov 2005

Posts: 115

i_learn

Default

in basic? was that not the 10 20 30 thing?
yea..........head fls method is spot on........alto you might not be able to run that in a loop..........
must confess that i had no idea that basic had those kind of loops........
i_learn is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On