fork download
  1. #include <stdio.h>
  2.  
  3. void cal (int x, int y, int *sum, int *diff, int *mul, int *quo){
  4. *sum = x + y;
  5. if(x<y){
  6. *diff = y - x;
  7. } else {
  8. *diff = x - y;
  9. }
  10. *mul = x * y;
  11. if(y!=0){
  12. *quo = x / y;
  13. } else {
  14. *quo = 0;
  15. }
  16. }
  17.  
  18. int main(){
  19. int x, y, sum, diff, mul, mod;
  20. printf("xの値を入力\n");
  21. scanf("%d", &x);
  22. printf("yの値を入力\n");
  23. scanf("%d", &y);
  24.  
  25. cal(x, y, &sum, &diff, &mul, &mod);
  26.  
  27. printf("xとyの和は%d\n", sum);
  28. printf("xとyの差は%d\n", diff);
  29. printf("xとyの積は%d\n", mul);
  30. printf("xとyの商は%d\n", mod);
  31.  
  32. return 0;
  33. }
  34.  
  35.  
Success #stdin #stdout 0.01s 5260KB
stdin
8
-2
stdout
xの値を入力
yの値を入力
xとyの和は6
xとyの差は10
xとyの積は-16
xとyの商は-4