我知道这是一个常见的问题.但是我找不到一个可靠的直接答案.
16 ^ 54 = 1.0531229167e+65 (this is the result I want)
Run Code Online (Sandbox Code Playgroud)
当我使用时pow(16,54),我得到:
105312291668557186697918027683670432318895095400549111254310977536.0
代码如下:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main(){
double public;
double a = 16;
double b = 54;
public = (pow(a,b));
printf("%.21f\n", public);
}
Run Code Online (Sandbox Code Playgroud)
执行代码:
gcc main.c -lm
我做错了什么?
das*_*ght 23
我究竟做错了什么?
几件事:
%.10e科学计数法格式,printf点后十位数的打印输出,int从你的回来main,public命名变量,可能需要将程序移植到C++,其中public是关键字.以下是修复程序的方法:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(){
double p;
double a = 16;
double b = 54;
p = (pow(a,b));
printf("%.10e\n", p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)