[cpp]
This is my C++ answer for 113.
I got WA. However, I don't understand why. I thought it perfectly solves the problem. Can anyone help me?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double n, k, p;
while (cin >> n >> p)
{
k = pow(p,(1/n));
cout << k << endl;
}
return 0;
} [/cpp]
Thanks for your reply.
I corrected the line and sent it. However, I got following compiler errors.
Also, when I run it on VC, I get no error but the output is funny. I mean, this doesn't solve the problem.
So if you have any thought on that, I appreciate it.
02143378_24.c: In function `int main ()':
02143378_24.c:14: `printf' undeclared (first use this function)
02143378_24.c:14: (Each undeclared identifier is reported only once for
each function it appears in.)
Thanks everyone. It worked.
But like how did you know that their compiler interpret it down to 6 decimal points and stuff like that?
Just out of curiosity.
No, double is enough. I have a similar solution, but with two more lines at the begining of the main function:
[cpp] cout.setf(ios::fixed);
cout.precision(0); [/cpp]
I don't remember why I put them there, but there must have been a reason
Krzysztof Duleba wrote:No, double is enough. I have a similar solution, but with two more lines at the begining of the main function:
[cpp] cout.setf(ios::fixed);
cout.precision(0); [/cpp]
I don't remember why I put them there, but there must have been a reason
I fix the code
[cpp] cout<<(long)pow(p,(double)1/n)<<endl [/cpp]
and some answers will be decrease like 1234->1233
so i think the answers' form i calculate are wrong......
i am trying to use the double data type but if i input a number having more than say 20 digits and then just print it ( no processing ) , i am not getting the same number that i had entered. after 20 digits the precision is lost.
could anyone pls suggest why it is so?