0

What does this step mean s=s+(double)i/(i+1)

need fast answer as soon as possible

28th Jan 2019, 10:43 AM
Anamika Thakur Saklani
Anamika Thakur Saklani - avatar
3 Answers
+ 12
Please provide with code & other information like datatype of variable s & i (though looks like variable of i is of type int (not double type), data type of s can create a difference in answer) to get better help from community. //can also be written as "s+=(double)i/(i+1)"
28th Jan 2019, 12:14 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
When performing a division, if both operands are integers, the euclidian division will be used. To prevent that, you need to cast at least one of the operands into a float or double, which is done here.
28th Jan 2019, 12:14 PM
Zen
Zen - avatar