C++ double giving wrong answer for Just 17 DIGITS !!!

Правка en3, от dawud, 2021-08-19 13:23:21

Hi, Recently while practicing I found this problem, Please run this code in your local machine.

Code

If you run this code you should see something like this

Output

Your can also see this code running in IDEONE
You can see there from i = 16 , the program is giving wrong output.
There should be all 1s in every number.
Can anyone please tell me

  • Why this is giving wrong result even in this small range ?
  • And how to avoid this type of calculation problem ?

Thanks in advance ❤️❤️❤️

Теги double, calculation, #c++17(64), wrong ouput

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский dawud 2021-08-19 13:23:21 2 Tiny change: ', \nRecent while pra' -> ', \nRecently while pra'
en2 Английский dawud 2021-08-19 13:22:50 4
en1 Английский dawud 2021-08-19 13:21:20 1097 Initial revision (published)