I wrote this code by mistake.
I know it should be 2*i
instead of 2i
, naturally, but compiler does not give any error messages. What is the reason?
double getpi(int terms){
int i;
double answer = 0;
for(i = 1; i <= terms; i++){
if (i % 2 == 1){
answer = answer + (4.0/(2i - 1));
}else{
answer = answer - (4.0/(2i - 1));
}
}
return answer;
}
I tried to check that values with debugger, but it confuses me more. The value of answer
is 0.