Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to simplify a number which contains fractional part like double or floating point number. We have done it at our low classes in arithmetic mathematics. Now I want to implement that thinking in C Programming. We may check some conditions given bellow.

If |number| > 1 and a fractional number then I want the result as n b/c here n is integer number.

b) If |number| < 1 and a fractional number then I expect the result as b/c

For better understanding I'm giving some examples:

a) If the number be 5.5 then I expect it as 5 1/2 which is equivalent to (5*2 + 1 == 11/2 == 5.5)

b) If the number be 0.7 then I expect it as 7/10 c) If the number be -0.5 then I expect it as -1/2

I'm trying actually to get result should be printed like this.
C++
#include <stdio.h>

int main()
{   
    double number;
    number = 5.5;

    if(number>1) printf("number %lf should be printed like: 5 1/2", number);
    printf("\n");

    number = 0.5;
    if(number<1) printf("number %lf should be printed like: 1/2", number);

    return 0;
}   
Posted
Updated 1-May-14 19:11pm
v3

1 solution

 
Share this answer
 
Comments
DamithSL 1-May-14 23:45pm    
i think OP want in c++ (questions should tag correctly, not your fault :))
PIEBALDconsult 1-May-14 23:52pm    
I'm sure the code can be translated to another language.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900