fork(1) download
  1. #include <assert.h>
  2.  
  3. int Floor(double x) {
  4. const int int_part = (int)x;
  5.  
  6. if (int_part >= 0) {
  7. return int_part;
  8. } else {
  9. return int_part - (x != int_part);
  10. }
  11. }
  12.  
  13. int Ceil(double x) {
  14. const int int_part =(int)x;
  15.  
  16. if (int_part < 0) {
  17. return int_part;
  18. } else {
  19. return int_part + (x != int_part);
  20. }
  21. }
  22.  
  23. int main() {
  24. assert(Ceil(0.0) == 0);
  25. assert(Floor(0.0) == 0);
  26.  
  27. assert(Ceil(1.0) == 1);
  28. assert(Floor(1.0) == 1);
  29.  
  30. assert(Ceil(-1.0) == -1);
  31. assert(Floor(-1.0) == -1);
  32.  
  33. assert(Ceil(1.2) == 2);
  34. assert(Floor(1.2) == 1);
  35.  
  36. assert(Ceil(-1.2) == -1);
  37. assert(Floor(-1.2) == -2);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 1784KB
stdin
Standard input is empty
stdout
Standard output is empty