C # Problem four / study

Title ④: enter a positive integer, and if it is odd, it is multiplied by 1 plus 3, if it is even, it is divided by 2, kept in operation on the results obtained in the same manner, eventually 1 can be obtained, which is known Kakutani conjecture. Please programming, the output calculation process, such as:

Input: 6

Output: 63105168421

 

It involves knowledge of grammar: nothing to say.

 

 1 static void PrintfourSolution()
 2         {
 3             int num = Convert.ToInt32(Console.ReadLine());
 4             Console.WriteLine(num);
 5             while(num!=1)
 6             {
 7                 if(num%2==1)
 8                 {
 9                     num = num * 3 + 1;
10                 }
11                 else
12                 {
13                     num /= 2;
14                 }
15                 Console.WriteLine(num);
16             }
17         }

 

Guess you like

Origin www.cnblogs.com/wu199723/p/11537289.html