Find Square Root of a Number
Here you will get an example code of C++ Program to Find Square Root of a Number. To calculate the square root in c++, we can use the sqrt() function defined in math.h header file.
Example of C++ Program to Find Square Root of a Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream.h> #include <math.h> using namespace std; int main() { float num, sqrtNum; // Input a number cout << "Enter a number : "; cin >> num; // Calculate square root sqrtNum = sqrt(num); // Print the result cout << "Square root of " << num << " is " << sqrtNum; return 0; } |
Output
Enter a number : 16
Square root of 16 is 4
Check out our other C++ programming Examples