方法一:for循環實現 程序: #include<stdio.h> int main() { double i = 0, t = 0,sum = 0,sign = -1; for (i = 1; i <= 100; i++) { sign = -sign; t =sign/ i; sum = sum + t; } printf("sum=%lf\n",sum); return 0; } 方法二:while循環實現 程序: #include<stdio.h> int main() { double i = 1, t = 0,sum = 0,sign = -1; while (i <= 100) { sign = -sign; t =sign/ i; sum = sum + t; i++; } printf("sum=%lf\n",sum); return 0; } 方法三:do...while循環實現 #include<stdio.h> int main() { double i = 1, t = 0,sum = 0,sign = -1; do { sign = -sign; t =sign/ i; sum = sum + t; i++; } while (i <= 100); printf("sum=%lf\n",sum); return 0; } 結果: sum=0.688172 請按任意鍵繼續. . .