Cube Root Program in C++

Google Advertisements

Prev Tutorial Next Tutorial

Cube Root of Number in C++

To find cube root of any number we need to find 0.3 power of any number. For example if you need to find cube root of 27 then calculate 0.3 power of 27, result is 3. And one another method for this program is use cbrt() function it is pre-defined in math.h header file.

Cube Root program in C++

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main() 
{ 
int num, ans; 
clrscr(); 
cout<<"Enter any number"; 
cin>>num; 
ans=pow(num, 1.0/3.0);
ans++;
cout<<"\n\Cube of "<<num<<" is: "<<ans; 
getch(); 
}

Output

Enter any Number: 27
Cube of 27 is: 3

Explanation of Program

  • Here we receive any number from keyboard and after that we find 1.0/3.0 power of number because square root of any number means power of 1/3.
  • pow() is a predefined function in math.h header file, it is used for calculate power of any number.

C++ program to find Cube Root

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main() 
{ 
int num,ans; 
clrscr(); 
cout<<"Enter any Number: "; 
cin>>num; 
ans=cbrt(num);;
cout<<"\n Cube Root of "<<num<<" is: "<<ans; 
getch(); 
} 

Output

Enter any Number: 27
Cube Root of 27 is: 3

Explanation of Code

cbrt() is a predefined function in math.h header file, it is used for calculate cube root of any number.

Cube Root of number using user defined function

Cube Root program in C++

#include<iostream.h>
#include<conio.h>

int cube(int); 
void main() 
{ 
int num; 
clrscr(); 
cout<<"Enter any number"; 
cin>>num; 
cout<<"\n\Cube of "<<num<<" is: "<<cube(num); 
getch(); 
} 
int cube(int num) 
{ 
int ans; 
ans=pow(num, 0.3);
ans++; 
return(ans); 
getch(); 
}

Output

Enter any Number: 64
Cube of 64 is: 4

Explanation of Program

  • Here we receive any number from keyboard and after that we multiply number by 0.33333 because square root of any number means power of 1/3 and 1/3=0.33333.
  • pow() is a predefined function in math.h header file, it is used for calculate power of any number.

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483