You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
537 B
23 lines
537 B
16 years ago
|
// A simple program that computes the square root of a number
|
||
5 years ago
|
#include <cmath>
|
||
|
#include <cstdlib>
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
16 years ago
|
|
||
9 years ago
|
int main(int argc, char* argv[])
|
||
16 years ago
|
{
|
||
9 years ago
|
if (argc < 2) {
|
||
5 years ago
|
std::cout << "Usage: " << argv[0] << " number" << std::endl;
|
||
16 years ago
|
return 1;
|
||
9 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
// convert input to double
|
||
|
const double inputValue = atof(argv[1]);
|
||
5 years ago
|
|
||
5 years ago
|
// calculate square root
|
||
|
const double outputValue = sqrt(inputValue);
|
||
5 years ago
|
std::cout << "The square root of " << inputValue << " is " << outputValue
|
||
|
<< std::endl;
|
||
16 years ago
|
return 0;
|
||
|
}
|