fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int incr(int x){
  5. return (x+1);
  6. }
  7.  
  8. int add(int x, int y){
  9. for (int i=0;i<x;i++)
  10. y = incr(y);
  11. return y;
  12. }
  13.  
  14. int decr(int x){
  15. int y = 0;
  16. int z = 0;
  17. for (int i=0;i<x;i++){
  18. y = z;
  19. z = incr(z);
  20. }
  21. return y;
  22. }
  23.  
  24. int sub(int x, int y){
  25. for (int i=0;i<y;i++)
  26. x = decr(x);
  27. return x;
  28. }
  29.  
  30. bool isZero(int x) {
  31. bool y = true;
  32. for (int i=0;i<x;i++)
  33. y = false;
  34. return y;
  35. }
  36.  
  37. bool lte(int x, int y){
  38. int z = sub(x, y);
  39. z = isZero(z);
  40. return z;
  41. }
  42.  
  43. bool gt(int x, int y){
  44. int z = lte(x, y);
  45. z = isZero(z);
  46. return z;
  47. }
  48.  
  49. int div_ceil(int x,int y){
  50. int r = 0;
  51. int t = x;
  52. for (int i=0;i<x;i++){
  53. int z = 0;
  54. int l = gt(t,z);
  55. r = add(r,l);
  56. t = sub(t,y);
  57. }
  58. return r;
  59. }
  60.  
  61. int div_floor(int x,int y){
  62. int r = 0;
  63. int t = 0;
  64. for (int i=0;i<x;i++){
  65. t = add(t,y);
  66. int l = lte(t,x);
  67. r = add(r,l);
  68. }
  69. return r;
  70. }
  71.  
  72. int main(){
  73. cout << "Checking div_ceil(x,y)" << endl;
  74. cout << div_ceil(0,5) << endl;
  75. cout << div_ceil(5,7) << endl;
  76. cout << div_ceil(10,10) << endl;
  77. cout << div_ceil(10,2) << endl;
  78. cout << div_ceil(10,3) << endl;
  79.  
  80. cout << "Checking div_floor(x,y)" << endl;
  81. cout << div_floor(0,5) << endl;
  82. cout << div_floor(5,7) << endl;
  83. cout << div_floor(10,10) << endl;
  84. cout << div_floor(10,2) << endl;
  85. cout << div_floor(10,3) << endl;
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Checking div_ceil(x,y)
0
1
1
5
4
Checking div_floor(x,y)
0
0
1
5
3