fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define macro(n) for(k=0;k<n;k++)sum+=1/(float)(k+1)
  4. int main(void)
  5. {
  6. int k,n;
  7. float sum = 0.0f;
  8. printf("請輸入第n項\n");
  9. scanf("%d", &n);
  10. printf("輸入的n為:%d\n",n);
  11. printf("計算1/1+1/2+1/3+‧‧‧+1/n的輸出結果為\n");
  12. macro(n);
  13. printf("sum = %f\n", sum);
  14. system("pause");
  15. return 0;
  16. }
  17.  
  18.  
Success #stdin #stdout #stderr 0.02s 5488KB
stdin
10000000
stdout
請輸入第n項
輸入的n為:10000000
計算1/1+1/2+1/3+‧‧‧+1/n的輸出結果為
sum = 15.403683
stderr
sh: 1: pause: not found