Zeno is having his friend Eno over for tea. He pours a cup for Eno, then for him
ID: 3870967 • Letter: Z
Question
Zeno is having his friend Eno over for tea. He pours a cup for Eno, then for himself. But he pours his own cup in a diminishing way: First he pours ½ a cup; then adds ¼ of a cup, then of a cup, etc., pouring half the previous amount each time. Construct a loop that calculates how full the cup is after a given number of pours, and try it out for a few numbers, such as 10, 50, 53, 54, 100, and 10,000. Paste your answer to these two questions in the Online Text Area: 1. How many pours before Zeno's cup runneth over? 2. How many additional cups should Zeno have handy to catch the overflow if he pours 100,000 times?Explanation / Answer
float j=1f;
float cupValue=0f;
float count=0f;
float numOfPours=100000f;
while(count<=numOfPours)
{
j=j*2;
cupValue+= 1f/j;
if((1f/j)==0.0f)
{
System.out.print("pouring cup is empty at count:"+count);
break;
}
count++;
}
System.out.print("cupval:"+cupValue);
-------------------------------------------------------------
output:
for 10 pours: cupval:0.9995117
for 50 pours: cupval:1.0
for 53 pours: cupval:1.0
for 54 pours: cupval:1.0
for 100 pours: cupval:1.0
for 10,000 pours: pouring cup is empty at count:127.0 cupval:1.0
Ans 1. After 24 pours zenoth cup ruuneth over by given loop we can calculate it
Ans 2. Zeno have not required extra cup because after 127 times of puring cup is empty.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.