tutorial.cxx 719 B

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