fork download
  1. #include <stdio.h>
  2. /* 函数功能:用迭代法计算n! */
  3. long Fact(int n)
  4. { /* 函数定义 */
  5. int i;
  6. long result = 1;
  7. for (i = 2; i <= n; i++) {
  8. result = result * i;
  9. }
  10. return result;
  11. }
  12. int main(void)
  13. {
  14. int m;
  15. long ret;
  16. printf("Input m:");
  17. scanf("%d", &m);
  18. ret = Fact(m);
  19. printf("%d! = %ld\n", m, ret);
  20. return 0;
  21. }
Success #stdin #stdout 0s 5348KB
stdin
6
stdout
Input m:6! = 720