fork download
  1. #include <stdio.h>
  2.  
  3. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod)
  4. {
  5. *sum = x + y; // 和
  6.  
  7. // 差は必ず正の整数(絶対値)
  8. if (x >= y) {
  9. *diff = x - y;
  10. } else {
  11. *diff = y - x;
  12. }
  13.  
  14. *mul = x * y; // 積
  15.  
  16. *mod = x / y; // 商(整数同士の割り算 → 小数点以下は自動で切り捨て)
  17. }
  18.  
  19. int main(void)
  20. {
  21. int x, y;
  22. int sum, diff, mul, mod;
  23.  
  24. printf("x と y を入力してください: ");
  25. scanf("%d %d", &x, &y);
  26.  
  27. cal(x, y, &sum, &diff, &mul, &mod);
  28.  
  29. printf("sum = %d\n", sum);
  30. printf("diff = %d\n", diff);
  31. printf("mul = %d\n", mul);
  32. printf("mod = %d\n", mod);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5320KB
stdin
26 9
stdout
x と y を入力してください: sum  = 35
diff = 17
mul  = 234
mod  = 2