using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int[] number = new int[11]; int i = 0; Random rd = new Random(); for (i = 0; i < 10; i++) { number[i] = rd.Next(1, 101); } Console.WriteLine("原始数据:"); for (i = 0; i < 10; i++) { Console.Write(number[i] + "\t"); } Array.Sort(number); Console.WriteLine("\n排序后:"); for (i = 0; i < 10; i++) { Console.Write(number[i] + "\t"); } Console.Write("\n要插入的数据:"); int num = Convert.ToInt32(Console.ReadLine()); int site = 0; for (i = 0; i < 10; i++) { if (number[i] > num) { break; } } site = i; for (i = number.Length - 2; i > site; i--) { number[i + 1] = number[i]; } number[site] = num; Console.WriteLine("\n插入后的数组:"); for (i = 0; i < 11; i++) { Console.Write(number[i] + "\t"); } Console.WriteLine(); Console.ReadLine(); } }}这下面的代码是什么意思啊 for (i = 0; i < 10; i++) { if (number[i] > num) { break; } } site = i; for (i = number.Length - 2; i > site; i--) { number[i + 1] = number[i]; } number[site] = num;
添加回答
举报
0/150
提交
取消