fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int a,b,q,r,sw;
  6. printf("整数を入力:\n"); scanf("%d %d",&a,&b);
  7. if(a%b == 0)
  8. {
  9. q = a / b;
  10. sw = 0;
  11. }
  12. else
  13. {
  14. q = a / b;
  15. r = a % b;
  16. sw = 1;
  17. }
  18. switch(sw)
  19. {
  20. case 0: printf("%d÷%d=%d\n",a,b,q); break;
  21. case 1: printf("%d÷%d=%d余り%d\n",a,b,q,r); break;
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5224KB
stdin
12
4
stdout
整数を入力:
12÷4=3