首页 > 试题广场 >

#includeusing&nb...

[单选题]
#include<bits/stdc++.h>
using namespace std;
int solve(int x){
if(x == 0 || x == 1){
return x;
}
if(x % 2 == 0){
return 1 + solve(x / 2);
}
else{
return 1 + solve((x + 1) / 2);
}
}
int main(){
int n = 100;
int ans = solve(n);
cout<<ans<<endl;
return 0;
}
程序的输出为(      )
  • 6
  • 7
  • 8
  • 9

2/2=1不是0

发表于 2019-10-14 10:53:50 回复(0)
100,50,25,14,8,4,2,0 递归7层再加上原来的=1+1+1+1+1+1+1+1
发表于 2019-08-26 17:05:12 回复(0)