还是要重思考!
#include<bits/stdc++.h>
using namespace std;
int f(int n){
return n==1?1:f(n/2)+1;
}
int main()
{
int n;
while(scanf("%d",&n)==1){
printf("%d\n",f(n));
}
return 0;
}
本文介绍了一个简单的递归函数实现方式,该函数用于计算输入整数的特定值。通过递归调用自身来达到最终目的,直到达到基本情况。文章包含完整的 C++ 代码示例。
还是要重思考!
#include<bits/stdc++.h>
using namespace std;
int f(int n){
return n==1?1:f(n/2)+1;
}
int main()
{
int n;
while(scanf("%d",&n)==1){
printf("%d\n",f(n));
}
return 0;
}
335

被折叠的 条评论
为什么被折叠?