fork download
  1. #include <stdio.h>
  2.  
  3. // 関数の宣言
  4. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod);
  5.  
  6. int main() {
  7. // 整数x, y, sum, diff, mul, modを定義
  8. int x, y, sum, diff, mul, mod;
  9.  
  10. // x, y の値を入力
  11. printf("Enter two integers (x and y): ");
  12. scanf("%d %d", &x, &y);
  13.  
  14. // cal関数を呼び出して計算を実行
  15. cal(x, y, &sum, &diff, &mul, &mod);
  16.  
  17. // 計算結果を表示
  18. printf("Sum (x + y): %d\n", sum);
  19. printf("Difference (|x - y|): %d\n", diff);
  20. printf("Multiplication (x * y): %d\n", mul);
  21. printf("Division (x / y, truncated): %d\n", mod);
  22.  
  23. return 0;
  24. }
  25.  
  26. // cal関数の定義
  27. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod) {
  28. // 和を計算
  29. *sum = x + y;
  30.  
  31. // 差を計算(絶対値)
  32. *diff = (x > y) ? (x - y) : (y - x);
  33.  
  34. // 積を計算
  35. *mul = x * y;
  36.  
  37. // 商を計算(小数点以下切り捨て)
  38. *mod = x/y ;
  39. }
Success #stdin #stdout 0s 5272KB
stdin
1
2
stdout
Enter two integers (x and y): Sum (x + y): 3
Difference (|x - y|): 1
Multiplication (x * y): 2
Division (x / y, truncated): 0