For a school assignment we are supposed to write a short piece of code that calculates the telescopic limit up to 100. The expect answer should be sum is: 0.99000
but my output is always sum is: 0.00000
no matter what I try.
I hope it is a quick fix that I have been overlooking, but I can't, for the life of me, figure out what it is.
here is my code below:
#include <stdio.h>
int main(){
float ans=0.0;
for(int i=1; i<100; i++){
ans += 1/ (i*(i+1));
}
printf("sum is: %.5f",ans);
return 0;
}