关于CSP-J1 T28
  • 板块学术版
  • 楼主zsh_haha
  • 当前回复10
  • 已保存回复10
  • 发布时间2024/9/21 17:47
  • 上次更新2024/9/21 18:23:35
查看原帖
关于CSP-J1 T28
757139
zsh_haha楼主2024/9/21 17:47

这里输入 yy 为负数,等 yy 减到 2147483648-2147483648 时,就会爆 int,变成 21474836472147483647,所以不会无限递归,只是会爆栈。

所以求问是不是应该打叉。

原题:

27.当输入为“2 3”时,customFunction(2,3)的返回值为“64”。( )

代码:

#include <iostream>
#include <cmath>
using namespace std;
int customFunction(int a, int b) {
	cout<<b<<endl;
	if (b == 0) {
		return a;
	}
	return a + customFunction(a , b - 1);
}
int main() {
	int x, y;
	cin >> x >> y;
	int result = customFunction(x, y);
	cout << pow(result, 2) << endl;
	return 0;
}
2024/9/21 17:47
加载中...