cubit root

How can i find cubit root?
You mean Cube root?

1
2
3
4
5
6
7
8
9
10
11
12
template<typename T>
T CubeRoot(T param)
{
	return param >> 3;
}

int main()
{
	cout << CubeRoot<int>(27);
	cin.ignore();
	return 0;
}



Program output:
3


cube root of 27 is 3 :)
Last edited on
@codekiddy, why did you use cin.ignore(); when there was no cin?
I think he mean we should ignore his answer.
Hi Gregory,
why did you use cin.ignore(); when there was no cin?


Maybe to stop a console?

not everybody use use unix or amiga computers :D
Not sure if that was a serious answer. There is a function in file <cmath> called 'pow' which can be used to find a cube root.
I alreadt found it. Pow can only power them but cant take roots. n-th root comes from here exp(log(abs(x))/n)) nth root from x.
Cube root using std::pow looks like this one:
pow(27, 1 / 3.f);
There is a function in <cmath> called std::cbrt as well: http://ideone.com/27aBq
Topic archived. No new replies allowed.