Can someone explain to me why the output is not 1.1 ?
And also please do explain why it is blank screen. #C
Attachments:
sharmila193:
Hi
Answers
Answered by
1
Interesting problem.
The answer to why no output is shown lies in the fact that float cannot accurately represent numbers, and is correct only upto a certain number of decimal places.
for example, the value of x in your problem is set to 1.1
However, that is only correct upto a few decimal places.
Printing the value of x correct upto 20 decimal places gives 1.10000002384185791016 (check it here: https://repl.it/@piratedvirus/httpsbrainlyinquestion3790179)
1.10000002384185791016 is not equal to 1.1 but slightly greater than it and hence the program never enters the while loop.
The same program will run if you use x >= 1 instead of x == 1 in the conditional part of your while loop.
Thank you.
The answer to why no output is shown lies in the fact that float cannot accurately represent numbers, and is correct only upto a certain number of decimal places.
for example, the value of x in your problem is set to 1.1
However, that is only correct upto a few decimal places.
Printing the value of x correct upto 20 decimal places gives 1.10000002384185791016 (check it here: https://repl.it/@piratedvirus/httpsbrainlyinquestion3790179)
1.10000002384185791016 is not equal to 1.1 but slightly greater than it and hence the program never enters the while loop.
The same program will run if you use x >= 1 instead of x == 1 in the conditional part of your while loop.
Thank you.
Answered by
0
Sorry but I did,nt know
Similar questions