每当我将5写成n,p写成2时,我得到的输出是24...please,它让我知道出了什么问题?对于其他数字,这是完全没有问题的。
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
double n, p;
cout << "enter the number" <<endl;
cin >> n;
cout << "enter the power" <<endl;
cin >> p;
int result = pow(n, p);
cout << "Result is " << result;
return 0;
}发布于 2017-07-03 22:20:29
您的数据类型有问题!
double n, p; // here you use double types
std::cout << "enter the number" << std::endl;
std::cin >> n;
std::cout << "enter the power" << std::endl;
std::cin >> p;
int result = pow(n, p); // then here you use double pow(double, double) but assign it to an int
std::cout << "Result is " << std::result;解决方案:
double result = pow(n, p);https://stackoverflow.com/questions/44887872
复制相似问题