Cube Root Program in C++

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++

Advertisements

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

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

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements