fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a, b;
  5. printf("二つの数字を入力してください: ");
  6. scanf("%d %d", &a, &b);
  7.  
  8. if (b == 0) {
  9. printf("0では割れません\n");
  10. return 1;
  11. }
  12.  
  13. int quotient = a / b;
  14. int remainder = a % b;
  15.  
  16. switch (remainder) {
  17. case 0:
  18. printf("%d ÷ %d = %d\n", a, b, quotient);
  19. break;
  20. default:
  21. printf("%d ÷ %d = %d 余り %d\n", a, b, quotient, remainder);
  22. break;
  23. }
  24.  
  25. return 0;
  26. }
  27.  
  28.  
Success #stdin #stdout 0.01s 5288KB
stdin
11  5
stdout
二つの数字を入力してください: 11 ÷ 5 = 2 余り 1