Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Check whether a given number is a perfect cube or not

C++ Numbers: Exercise-32 with Solution

Write a program in C++ to check whether a given number is a perfect cube or not.

Sample Solution:

C++ Code :

#include<iostream>
#include<math.h>
using namespace std;
int main() 
{ 
int num, curoot,ans; 

 cout << "\n\n Check whether a number is a perfect cube or not: \n";
 cout << " -----------------------------------------------------\n";
    cout<<" Input a number: ";
    cin>>num;
curoot=round(pow(num, 1.0/3.0));

if(curoot*curoot*curoot==num)
{
  cout<<" The number is a perfect Cube of "<<curoot<<endl;   
}
else
{
  cout<<" The number is not a perfect Cube."<<endl;   
}
}

Sample Output:

Check whether a number is a perfect cube or not:                      
 -----------------------------------------------------                 
 Input a number: 8                                                     
 The number is a perfect Cube of 2 

Flowchart:

Flowchart: Check whether a given number is a perfect cube or not

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to find circular prime numbers upto a specific limit.
Next: Write a program in C++ to display first 10 Fermat numbers.

What is the difficulty level of this exercise?