gpt4 book ai didi

c++ - 如何计算以下c程序中的运行时内存和最大数据内存使用量

转载 作者:行者123 更新时间:2023-11-30 16:46:26 24 4
gpt4 key购买 nike

这是我的代码

运行时内存将取决于操作系统,但我不想要那个级别。只想从基础级别解决此类问题。

include <studio.h>

int calculate(int n);

int number = 8;

int main(){

int add;

add = calculate(number);

return 0;

}

int calculate(int x){

if(x==0){

return x;

}else{

return x+calculate(x-1);

}

}

最佳答案

第一个问题,使用

#include <stdio.h> 

而不是

include <studio.h>

第二个问题,使用x而不是n

return x+calculate(x-1);

完整代码:

#include <stdio.h>

int calculate(int n);

int number = 8;

int main()
{
int add;

add = calculate(number);
printf("%d\n", add);
return 0;
}

int calculate(int x)
{
int n = 0;
if(x==0)
{
return x;
}
else
{
return x+calculate(x-1);
}
}

关于c++ - 如何计算以下c程序中的运行时内存和最大数据内存使用量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43731006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com