TutorialStudyMite
Square Root Program in C++
PPrabhnoor Maingi1 min read
Beginner friendly
Track completion, mastery, and revision.
Square Root of Number program in C++
# Important Points:
- Square root in C++ can be calculated using sqrt() function defined in <math.h> header file.
- sqrt() function takes a number as an argument and returns the square root of that number.
Example:
Given number: 1296
Square root: 36
# Algorithm
- Declare a variable called
numberto store the number whose cube root you want to calculate. - Declare a variable called
rootto store the result of the cube root calculation. - Prompt the user to enter the number whose cube root they want to calculate, and store the input in the
numbervariable. - Use the
sqrt()function from themathlibrary to calculate the cube root of thenumberand store the result in therootvariable. - Print the result stored in the
rootvariable to the console.
Code:
#include<iostream>
#include<math.h>
using namespace std;
int main(){
float number, root;
cout << "Enter number whose root is to be found: ";
cin >> number;
root = sqrt(number);
cout << "Square root of " << number << " is " << root;
return 0;
}
Output
Enter number whose root is to be found: 16
Square root of 16 is 4
Finished reading?