tutorial.cxx 769 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. double outputValue = 0;
  22. if(inputValue >= 0)
  23. {
  24. #ifdef USE_MYMATH
  25. outputValue = mysqrt(inputValue);
  26. #else
  27. outputValue = sqrt(inputValue);
  28. #endif
  29. }
  30. fprintf(stdout,"The square root of %g is %g\n",
  31. inputValue, outputValue);
  32. return 0;
  33. }