【发布时间】:2013-11-30 21:59:12
【问题描述】:
编写一个递归函数来检查数字中有多少位可以除以它们后面的数字。示例:84963 应该返回 2,因为 8 可以除以 4,6 可以除以 3。我的函数似乎根本没有输出任何内容。
#include <iostream>
using namespace std;
int fun (int n);
int main()
{
int n;
cin >> n;
cout << fun(n) << endl;
return 0;
}
int fun(int n){
int count = 0;
if (fun(n % 100) % fun(n % 10) == 0)
count++;
return count;
}
【问题讨论】:
-
你应该使用调试器并寻找值......你会学到很多东西
-
你试过我的建议了吗?通过使用 3 个参数而不是 1 个参数,您将提高内存使用率(在处理大数字时非常重要)