fork download
  1. #include <stdio.h>
  2.  
  3. unsigned long long product(int n) {
  4. unsigned long long result = 1;
  5. for (int i = 1; i <= n; i++) {
  6. result *= i;
  7. }
  8. return result;
  9. }
  10.  
  11. int main() {
  12. int n;
  13.  
  14. printf("n を入力してください(0以上の整数): ");
  15. scanf("%d", &n);
  16.  
  17. if (n < 0) {
  18. printf("エラー: 0以上の整数を入力してください。\n");
  19. return 1;
  20. }
  21.  
  22. unsigned long long result = product(n);
  23. printf("1から%dまでの積(%d!)は %llu です。\n", n, n, result);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
5
stdout
n を入力してください(0以上の整数): 1から5までの積(5!)は 120 です。