fork download
  1. // 14-1
  2. #include <stdio.h>
  3.  
  4. double ssk_wa;
  5. double ssk_sa;
  6. double ssk_seki;
  7. double ssk_shou;
  8.  
  9. int sisoku(double a, double b)
  10. {
  11. if (b == 0) {
  12. return -1; // ゼロ除算
  13. }
  14. ssk_wa = a + b;
  15. ssk_sa = a - b;
  16. ssk_seki = a * b;
  17. ssk_shou = a / b;
  18. return 0;
  19. }
  20.  
  21. int main()
  22. {
  23. double a, b;
  24. printf("変数aの値を入力\n");scanf("%lf", &a);
  25. printf("変数bの値を入力\n");scanf("%lf", &b);
  26. printf("a=%f, b=%f\n", a, b);
  27. if (sisoku(a, b)) {
  28. printf("Error:ゼロ除算\n");
  29. return 1;
  30. }
  31. printf("和:%f, 差:%f, 積:%f, 商:%f\n", ssk_wa, ssk_sa, ssk_seki, ssk_shou);
  32. return 0;
  33. }
Success #stdin #stdout 0.02s 1680KB
stdin
5
2
stdout
変数aの値を入力
変数bの値を入力
a=5.000000, b=2.000000
和:7.000000, 差:3.000000, 積:10.000000, 商:2.500000