tutorial.cxx 727 B

123456789101112131415161718192021222324252627282930313233
  1. // A simple program that computes the square root of a number
  2. #include "TutorialConfig.h"
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #ifdef USE_MYMATH
  7. #include "MathFunctions.h"
  8. #endif
  9. int main(int argc, char* argv[])
  10. {
  11. if (argc < 2) {
  12. fprintf(stdout, "%s Version %d.%d\n", argv[0], Tutorial_VERSION_MAJOR,
  13. Tutorial_VERSION_MINOR);
  14. fprintf(stdout, "Usage: %s number\n", argv[0]);
  15. return 1;
  16. }
  17. double inputValue = atof(argv[1]);
  18. double outputValue = 0;
  19. if (inputValue >= 0) {
  20. #ifdef USE_MYMATH
  21. outputValue = mysqrt(inputValue);
  22. #else
  23. outputValue = sqrt(inputValue);
  24. #endif
  25. }
  26. fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
  27. return 0;
  28. }