#include<stdio.h>
#include<math.h>
int main(void)
{
long int n;
scanf("%d",&n);
n=pow(10,n);
printf("%ld\n",n);
solve(n);
return 0;
}
最佳答案
您需要使用 double
,而不是 long
(因为 1080 不适合 64 位 long
code> 可以表示 9223372036854775807 以下的数字)。但请阅读the floating point guide ,因为这是一个非常困难的主题(请注意 floating point 数字与数学 real numbers 不同)。
你可以尝试:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
int n = 0;
if (scanf("%d",&n)<1) { perror("scanf"); exit(EXIT_FAILURE); };
if (n < -256 || n > 256)
{ fprintf(stderr, "wrong exponent %d\n", n);
exit(EXIT_FAILURE); };
double x = pow(10.0,(double)n);
printf("ten power %d is %g\n", n, x);
return 0;
}
(我删除了对您未定义的solve
的调用;我测试了scanf
是否成功以及n
的范围)
对于更大的指数,您需要 bignums也许使用 GMPlib .
编译时不要忘记启用所有警告和调试信息。如果您使用 gcc -Wall -Wextra -g
编译原始代码,您会收到多次警告(几乎每行一个警告!)。
关于c - 如何在 c 中存储 pow(10,n) 整数值,其中 n 可以 <200?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653894/