This C++ program computes the square root of a number using math library. The program takes input from the standard input, computes the value and prints it.
Here is the source code of the C++ program computes the square root of a number using math library. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Compute Square Root of a number using Standard Library
double output, input, min, max;
std::cout << "Enter the value : ";
std::cin >> input;
std::cout << std::endl;
min = std::numeric_limits<double>::min();
max = std::numeric_limits<double>::max();
if (input >= min && input <= max)
output = sqrt(input);
std::cout << "Square root of " << input
<< " = " << output << std::endl;
std::cerr << "Error: " << input << " not within limits"
Enter the value : 1024.0
Square root of 1024 = 32
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1,
- Chapterwise Mock Tests: Chapter 1,
, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry
. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms.
Stay connected with him at LinkedIn
Subscribe to his free Masterclasses at Youtube
& technical discussions at Telegram SanfoundryClasses