C++ program to find square root and cube root of number














































C++ program to find square root and cube root of number



 Description :-
 A wide number of useful mathematical functions are available in C++.
 These functions are included in standard C++ and can be used to
 perform a variety of mathematical calculations. These functions, 
 rather than focusing on implementation, can be used to immediately
 reduce code and applications. C++ has a significant number of
 mathematical functions. To utilize these functions, you must include
 the header files <math.h> and <cmath>.

 C++ sqrt( )
 The sqrt() function in C++ returns the square root of a number.
 This function is defined in the cmath header file. If the number is 
 not perfect square, then return floor(√x).

 C++ cbrt( )
 The cbrt() function in C++ returns the cube root of a number. This
 function is defined in the cmath header file. If the number is 
 not perfect cube, then return floor(3√x).

 parameter :- The sqrt( ) and cbrt( ) function takes a single argument
                       whose square root & cube root is to be calculated.

 Code
#include<iostream>
#include<cmath>

using namespace std;

void square_root(float number) {
double result = sqrt(number);
cout << "\nThe square root of the number is : "<< result ;
}

void cube_root(float number) {
double result = cbrt(number);
cout << "\nThe cube root of the number is : "<< result ;
}

int main() {
float num;
cout << "Enter number number : " ;
cin >> num;
square_root(num);
cube_root(num);
}


Output :-

Enter number number : 64
The square root of the number is : 8
The cube root of the number is : 4



Comments