22_floating_point.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5. // variables
  6. float a = 12.34 + 56.78;
  7. printf("%f\n", a);
  8. // infix operators
  9. printf("%f\n", 12.34 + 56.78);
  10. printf("%f\n", 12.34 - 56.78);
  11. printf("%f\n", 12.34 * 56.78);
  12. printf("%f\n", 12.34 / 56.78);
  13. // comparison operators
  14. printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78);
  15. printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34);
  16. printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34);
  17. // assignment operators
  18. a = 12.34;
  19. a += 56.78;
  20. printf("%f\n", a);
  21. a = 12.34;
  22. a -= 56.78;
  23. printf("%f\n", a);
  24. a = 12.34;
  25. a *= 56.78;
  26. printf("%f\n", a);
  27. a = 12.34;
  28. a /= 56.78;
  29. printf("%f\n", a);
  30. // prefix operators
  31. printf("%f\n", +12.34);
  32. printf("%f\n", -12.34);
  33. // type coercion
  34. a = 2;
  35. printf("%f\n", a);
  36. printf("%f\n", sin(2));
  37. return 0;
  38. }
  39. /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/