Cube Root Program in C++

Google Advertisements

Find Squre Root in C++ Ascii Value of Character in C++

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.

Find Squre Root in C++ Ascii Value of Character in C++

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

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. Difference between path and classpath in Java

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

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

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs