fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void show(int a, int b)
  7. {
  8. int q = a / b;
  9. int r = a % b;
  10. int addend = r > 0;
  11. int result = q + addend;
  12.  
  13. int quotient_ceiling = (int)ceil((double)a / b);
  14.  
  15. cout << "a = " << a << ", b = " << b <<
  16. ", division a/b produced " << q <<
  17. ", remainder = " << r <<
  18. ", result = " << result <<
  19. " (quotient ceiling = " << quotient_ceiling << ")" <<
  20. endl;
  21. }
  22.  
  23. int main()
  24. {
  25. show(11, 5);
  26. show(11, -5);
  27. show(-11, 5);
  28. show(-11, -5);
  29. return 0;
  30. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
a = 11, b = 5, division a/b produced 2, remainder = 1, result = 3 (quotient ceiling = 3)
a = 11, b = -5, division a/b produced -2, remainder = 1, result = -1 (quotient ceiling = -2)
a = -11, b = 5, division a/b produced -2, remainder = -1, result = -2 (quotient ceiling = -2)
a = -11, b = -5, division a/b produced 2, remainder = -1, result = 2 (quotient ceiling = 3)