Can I print rational numbers(Fractional) in floating point and in a/b format in the same time ?
if I can , How to create it in two function ?
Asked
Active
Viewed 72 times
1

Khan
- 53
- 1
- 7
-
How is your input of fractional numbers? – JuniorCompressor Feb 26 '15 at 19:10
-
yes only if a and b are given. – sithereal Feb 26 '15 at 19:10
-
1`printf('%f %d, %d\n', a/b, a, b)`, basically – Marc B Feb 26 '15 at 19:11
-
1`printf('%f %d/%d\n', a/b, a, b);` marc – JuniorCompressor Feb 26 '15 at 19:12
-
2@MarcB: Might be disappointed w/ floating point part if `a` & `b` are integers. – Scott Hunter Feb 26 '15 at 19:12
-
@JuniorCompressor for example 1/2 , I wanna print in 1/2 and 0.5 – Khan Feb 26 '15 at 19:13
-
2Come on guys ! It's a C++ tag ! I'd expected `cout << (double)a/b << " "< – Christophe Feb 26 '15 at 19:16
-
@ScottHunter: can't do ALL their homework for them... – Marc B Feb 26 '15 at 19:18
-
@Christophe please make it a class and a function – JuniorCompressor Feb 26 '15 at 19:19
-
1@Christophe It's C++ and then you use C-style casts? – edmz Feb 26 '15 at 20:15
-
Practically speaking, a floating point in binary representation is a fraction of a power of 2 (https://www3.ntu.edu.sg/home/ehchua/programming/java/DataRepresentation.html). So it would be possible to diplay any floating point as a fraction. The algortithm would depend on floating point representation. – Christophe Feb 26 '15 at 20:28