tutorial.cxx 537 B

12345678910111213141516171819202122
  1. // A simple program that computes the square root of a number
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <string>
  6. int main(int argc, char* argv[])
  7. {
  8. if (argc < 2) {
  9. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  10. return 1;
  11. }
  12. // convert input to double
  13. const double inputValue = atof(argv[1]);
  14. // calculate square root
  15. const double outputValue = sqrt(inputValue);
  16. std::cout << "The square root of " << inputValue << " is " << outputValue
  17. << std::endl;
  18. return 0;
  19. }