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 = 10, y = 3;
  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
10と3の和は13
10と3の差は7
10と3の積は30
10と3の商は3