fork download
  1. #include <stdio.h>
  2. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod);
  3.  
  4. int main() {
  5. // x, y, sum, diff, mul, mod の定義
  6. int x, y, sum, diff, mul, mod;
  7.  
  8. // x と y に値を入力
  9. printf("Enter two integers (x y): ");
  10. scanf("%d %d", &x, &y);
  11.  
  12. // cal 関数を呼び出して計算
  13. cal(x, y, &sum, &diff, &mul, &mod);
  14.  
  15. // 計算結果を表示
  16. printf("Sum: %d\n", sum);
  17. printf("Difference: %d\n", diff);
  18. printf("Product: %d\n", mul);
  19. printf("Quotient (integer division): %d\n", mod);
  20.  
  21. return 0;
  22. }
  23.  
  24. // cal 関数の定義
  25. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod) {
  26. // 和
  27. *sum = x + y;
  28.  
  29. // 差 (差は絶対値を取る)
  30. *diff = abs(x - y);
  31.  
  32. // 積
  33. *mul = x * y;
  34.  
  35. // 商 (整数の除算)
  36. if (y != 0) {
  37. *mod = x / y; // 整数の商を求める
  38. } else {
  39. *mod = 0; // ゼロ除算を防ぐため
  40. printf("Warning: Division by zero.\n");
  41. }
  42. }
  43.  
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
Enter two integers (x y): Sum: -1129697366
Difference: 1129707882
Product: -36626624
Quotient (integer division): -214854