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:
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?