tutorial.cxx 699 B

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