你如果是想通过输入n传给hailstone函数,程序这样写:
#include<stdio.h>
int hailstone(int n){
int length=1;
while(1<n){ (n%2)? n=3*n+1 : n/=2; length++;}
return length;
}
int main(){
int n=0, res=0;
scanf("%d", &n);
res = hailstone(n);
printf("res=%d", res);
return 0;
}
温馨提示:答案为网友推荐,仅供参考