Thread: Logic to convert the floating point no to fraction(numerator/denominator) format

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    Question Logic to convert the floating point no to fraction(numerator/denominator) format

    Please tell me logic of this program without using structures.
    Problem: given a no exp:3 you should display all combination of unique fractions in ascending order like as shown in example
    EXP:
    input: 3
    o/p:1/3 1/2 2/3 1/1

    hint:convertion Logic to convert the floating point no to fraction(numerator/denominator) format without using structures.
    examples:
    0.2 can be converted to 1/5 format
    .5 can be conveted to the 1/2 format
    2/3 can be conveted to the .667
    Last edited by tanmay_solanki; 08-25-2007 at 10:43 PM. Reason: a mistake

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    .5 is not 1/5, it's 1/2, See the rules regarding homework.

    * Make sure the decimal is terminating, ie finite, 2/3 is not finite you're going to have to do some approximation going from .667 -> 2/3
    * See http://homepage.smc.edu/kennedy_john/DEC2FRAC.PDF or research yourself

    If you have any specific questions, ask.
    Last edited by zacs7; 08-25-2007 at 05:46 AM.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    Smile thanks

    thanks for guiding me.I will be glad to have more replys from you for the future threads.
    Last edited by tanmay_solanki; 08-25-2007 at 10:57 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 0.2 can be converted to 1/5 format
    Consider that say 0.125 can be written as 125/1000
    Now research GCD and GCF to see how you might reduce it to 1/8
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Floating point #'s, why so much talk about it?
    By scuzzo84 in forum C Programming
    Replies: 5
    Last Post: 09-20-2005, 04:29 PM
  2. Head Banging Floating Point Conversions
    By Davros in forum C++ Programming
    Replies: 9
    Last Post: 02-23-2004, 09:23 AM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM
  4. how do you check for a floating point vlaue in c??
    By xenodvs1 in forum C Programming
    Replies: 4
    Last Post: 02-12-2003, 06:52 AM
  5. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM