Home > Back-end > For help, C language programming, code to run.
For help, C language programming, code to run.
Time:04-01
Most recent likes collecting COINS. What he likes is the 'one yuan coin which was made in1996 Jesus, no one knows according to he is so wild about it. These days he was not happy, because there was a fake coin among his COINS. The recent want to find it out, and What he has is an old balance. Since zinc is very lazy man, he want to know how many times at the most are men to find the fake coin in the worst situation. The fake coin is lighter than others and the rest have the same weight. Input format: Input a line, as an integer The output format: Output one line for an integer The sample input: 2 The sample output: 1 The sample input: 100 The sample output: 5
My code # include & lt; Stdio. H> Int main () { int n; Int time=0; The scanf (" % d ", & amp; N); For (;; ) { If (n==2 & amp; & N==3) { Time++; Printf (" % d ", time); break; } The else { If (n % 3==0) { Time++; N=n/3; } The else { Time++; N=((n - (n % 3))/(3) + (n % 3); } } } }
CodePudding user response:
Reference:
# include & lt; Stdio. H> Int main () { int n; Int time=0; The scanf (" % d ", & amp; N); For (;; ) { If (n==2 | | n==3)//if (n==2 & amp; & N==3) { Time++; Printf (" % d ", time); break; } The else { If (n % 3==0) { Time++; N=n/3; } The else { Time++; N=((n - (n % 3))/(3) + (n % 3); } } } return 0; }