Computer Science, asked by YuvrajSingh29, 1 year ago

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
sharmila193: Anyone there
YuvrajSingh29: hi
sharmila193: Hi
sharmila193: ru there
YuvrajSingh29: Yes! I am here.

Answers

Answered by piratedvirus
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.

YuvrajSingh29: Now I get it, thanks.
Answered by ShashiWWE
0
Sorry but I did,nt know
Similar questions