fork download
  1. #include <stdio.h>
  2.  
  3. void cal(int x, int y, int *sum, int *diff, int *mul, int *mod) {
  4. *sum = x + y;
  5. *diff = (x > y) ? (x - y) : (y - x); // 差の絶対値を格納
  6. *mul = x * y;
  7. *mod = x / y; // 商(小数点以下を切り捨て)
  8. }
  9.  
  10. int main(void) {
  11. int x = 3, y = 5;
  12. int sum, diff, mul, mod;
  13.  
  14. cal(x, y, &sum, &diff, &mul, &mod);
  15.  
  16. printf("%dと%dの和は%d\n", x, y, sum);
  17. printf("%dと%dの差は%d\n", x, y, diff);
  18. printf("%dと%dの積は%d\n", x, y, mul);
  19. printf("%dと%dの商は%d\n", x, y, mod);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
3と5の和は8
3と5の差は2
3と5の積は15
3と5の商は0