Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么c中的这个函数会产生意想不到的结果?_C - Fatal编程技术网

为什么c中的这个函数会产生意想不到的结果?

为什么c中的这个函数会产生意想不到的结果?,c,C,我正在学习C函数构造,我正在尝试用两个参数构造一个指数函数:基和指数 #include <stdio.h> #include <stdlib.h> int power(int a,int b){ int c; int i; c=1; for(i=1;i<=b;++i){ c=c*a; } return c; } int main(){ int nice=power(5,20);

我正在学习C函数构造,我正在尝试用两个参数构造一个指数函数:基和指数

#include <stdio.h>
#include <stdlib.h>


int power(int a,int b){

    int c;
    int i;
    c=1;

    for(i=1;i<=b;++i){
        c=c*a;
    }
    return c;
}

int main(){

    int nice=power(5,20);
    printf("answer =%d , and size is=%d ", nice, sizeof(nice));
    return 0;
}
#包括
#包括
整数功率(整数a、整数b){
INTC;
int i;
c=1;

对于(i=1;i它有整数溢出。您必须使用
无符号long-long
long-long

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;
ll power(ll a,ll b){

ll c,i;
c=1;

for(i=1;i<=b;++i){
    c=c*a;
}
return c;
}

int main(){

ll nice=power(5,20);
printf("answer =%lld , and size is=%lld ", nice, sizeof(nice));
return 0;
}
#包括
#包括
typedef long-long-ll;
ll电源(ll a、ll b){
ll c,i,;
c=1;
对于(i=1;我读了这个

问题2:a=5B=100会发生什么
然后,您必须编写用于处理乘法的自定义函数。使用int
arr[100]
要保留大数字的数字,然后将其相应地相乘。C/C++不提供类似
Java
BIgInt
,您必须构建它。

5^20是一个大数字,它不适合
int
。您期望的值是什么?谢谢它的工作。但我有一个问题。编译器正在抛出一个warning说“格式中未知的转换类型字符‘l’”,但它仍然有效。还有更多更大的数字呢?比如base=100和exponent=20?@coderredoc为什么
typedef
long-long-int
datatype?splotz90.:我实际上在竞争性编程中使用了很多这种方法。我会说习惯