fork download
  1. #include <stdio.h>
  2.  
  3. void test_float() {
  4. float d = 0.01f;
  5. float n = 0.0f;
  6. for (int i = 0 ; i < 100 ; ++i) {
  7. n += d;
  8. }
  9. if (n < 1.0) {
  10. printf("float: n (%f) < 1.0\n", n);
  11. } else {
  12. printf("float: n (%f) >= 1.0\n", n);
  13. }
  14. }
  15.  
  16. void test_double() {
  17. double d = 0.01;
  18. double n = 0.0;
  19. for (int i = 0 ; i < 100 ; ++i) {
  20. n += d;
  21. }
  22. if (n < 1.0) {
  23. printf("double: n (%f) < 1.0\n", n);
  24. } else {
  25. printf("double: n (%f) >= 1.0\n", n);
  26. }
  27. }
  28.  
  29. int main(void) {
  30. test_float();
  31. test_double();
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
float: n (0.999999) < 1.0
double: n (1.000000) >= 1.0