Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Hi programmers what the condition to sum the fraction number
1/2+1/3=5/6
2 Respostas
+ 1
Well you if a decimal approximation is good enough you can convert the fractionsāto floatingā point numbers first. Then add them.
If you need the fraction answer you can convert back by multiplying by different numbers until you get an integer. You allow for a tolerance like 1% or 0.01% etc. This because Floatingā point is anā approximationā, and recurring decimals don't always multiply up correctly.
If you want an easy error resistant to add fractionsā, then you can make yourā own data type, probably implementedā as a class.
Or you could see if there is a library available to do this already. I suggest boost rational:
http://www.boost.org/doc/libs/1_65_1/libs/rational/index.html
0
thank you jared šøšø