The problem is as follows:
1. Enter a positive integer n;
2. display n;
3. If n = 1, all operations are terminated;
4. If n is an odd number, n is changed to 3 * n + 1; otherwise, n is changed to n/2;
5. Transfer in step 2.
Problem Analysis:
This question is relatively simple. We only need to follow the requirements of the question step by step to find the result.
ReferenceCode:
# Include <iostream> using namespace STD; int Max, M; void Link (int n) {cout <n <''; m ++; if (n = 1) {cout <Endl; return;} If (N % 2 = 1) n = 3 * n + 1; Elsen = n/2; link (n) ;}int main () {int I, j; CIN >>> J; max = 0; For (int t = I; t <= J; t ++) {m = 0; cout <"when T is" <t <", its sequence is:"; Link (t ); cout <"when the positive integer value is" <t <", its chain length is" <m <Endl; If (M> MAX) max = m;} cout <"its longest chain length is" <max <Endl; return 0 ;}