fork download
  1. #include <stdio.h>
  2.  
  3. void divide_int(int dividend, int divisor, int *quotient, int *remainder) {
  4. if (divisor == 0) {
  5. *quotient = 0;
  6. *remainder = 0;
  7. return;
  8. }
  9.  
  10. *quotient = dividend / divisor;
  11. *remainder = dividend % divisor;
  12. }
  13.  
  14. int main() {
  15. int a, b;
  16. int q, r;
  17.  
  18. printf("2つの整数をスペース区切りで入力してください(例: 10 3): ");
  19. scanf("%d %d", &a, &b);
  20.  
  21. divide_int(a, b, &q, &r);
  22.  
  23. printf("%d ÷ %d の商 = %d, 余り = %d\n", a, b, q, r);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5272KB
stdin
17 5
stdout
2つの整数をスペース区切りで入力してください(例: 10 3): 17 ÷ 5 の商 = 3, 余り = 2