PAT真题时提示有部分正确,问错误地方在哪?
PAT乙级真题:#include <stdio.h>
int getTime(int n){
int count = 0;
while(n != 1){
if(n%2 == 0){
n /= 2;
}else{
n = (3*n+1)/2;
}
count++;
}
return count;
}
int main(int argc, char** argv) {
int n;
scanf("%d",&n);
n = getTime(n);
printf("%d",n);
return 0;
}
#include<stdio.h>
int main(){
int n,i=0;
scanf("%d",&n);
while(n>1&&n<1000){
if(n%2!=0){
n=(3*n+1)/2;
i++;
}
if(n%2==0){
n=n/2;
i++;
}
}
printf("%d",i);
}