I have the following code:
pim = 1;
for(i=1;i<=n;i++){
pim *= (2*i/(2*i-1))*(2*i/(2*i+1));
}
printing pim returns 0.0000... (iyn are int, pim is float).
no matter what value you give an it always returns 0
I have the following code:
pim = 1;
for(i=1;i<=n;i++){
pim *= (2*i/(2*i-1))*(2*i/(2*i+1));
}
printing pim returns 0.0000... (iyn are int, pim is float).
no matter what value you give an it always returns 0
The division with ints is what in mathematics is called a
división entera por defecto
.So, since in the factor
(2*i/(2*i+1))
for i > 0, the divisor is always greater than the dividend, the quotient will always be 0. And the product of two factors where at least one of them is zero will also be 0.