I am writing a program which checks if a given number has a integer cube root. Here is my code:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[])
{
double m;
int c=0;
int i;
for(i=2;i<=1000000;i++)
{
m = pow(i,(1./3.));
if(m-(int)m == 0)
{
c++;
}
}
cout<<c<<endl;
}
Here c
stores the number of numbers which have a integer cube root. The problem with my code is that it always gives two as the answer while answer should be greater than two as there are many numbers like 8,64,27,...
I want to know why I get the result as two. I am not able to catch the bug!