首页 > 试题广场 >

程序的输出为( )

[单选题]
#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
直接按照程序的运行顺序进行运算 选C


发表于 2019-09-29 21:54:18 回复(0)
x值变化顺序:100、50、25、13、7、4、2、1,一共8次
发表于 2019-09-29 17:23:58 回复(0)