using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { double integer=0,result=0; //integer:正整数; Console.WriteLine("请输入一个正整数"); integer = Convert.ToDouble(Console.ReadLine()); do { Console.Write("第{0}次{1}------->", result, integer); if (integer % 2 == 0) integer /= 2; else integer=integer*3+1; result++; Console.WriteLine("{0}", integer); } while (integer!=1); Console.WriteLine("经过{0}次这样的运算才得到数1", result); Console.Read(); } } }
时间: 2024-10-13 01:11:58