+ 1

Can we get fraction result in c++ ?

Example : 4/18 = 2/9 //in normal divison// But in c++, we get 0.22222 // in c++ //

19th Mar 2022, 8:58 AM
Gagan Gajendra
1 Antwort
+ 1
First calculate the gcd for the numerator and the denominator then divide the numerator and the denominator by that value and you should have your result. (if you have c++17) https://en.cppreference.com/w/cpp/numeric/gcd
19th Mar 2022, 9:32 AM
Dennis
Dennis - avatar