/* error6.c 積み残し現象 1/1 + 1/2 + 1/3 + ... は無限大だが ... */ #include #include main() { int c = 0, i = 0; float x = 0.0, y = -1.0; while(x != y){ i++; c++; y = x; x += 1.0/i; if(c == 100000){ printf("1/1 + 1/2 + ... + 1/%7d = %9.6f\n",i,x); c = 0; } } printf("ここから和の値が増えなくなりました:\n",i); printf("1/1 + 1/2 + ... + 1/%7d = %9.6f\n",i,x); }