首页 > 代码库 > 作业1226

作业1226

1.在案例一的基础上,显示球员总分和平均分以及显示最高分和最低分,以及相应球员的代号。

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace ConsoleApplication1 7 { 8     class Class2 9     {10         static void Main(string[] args)11         {12             int[] a = new int[6];13             Console.WriteLine("********球员训练记录********");14 15             for (int i=0;i<a.Length;i++)16             {17                 Console.Write("请输入第"+(i+1)+"个球员的成绩:");18                 a[i] =Convert.ToInt32( Console.ReadLine());19             }20 21             for (int m = 0; m < a.Length; m++)22             {23                 Console.WriteLine(""+(m+1)+"个球员的成绩是"+a[m]+"");24             }25 26             int sum = 0;27             double ave = 0; 28             for (int n = 0; n < a.Length;n++ )29             {30                 sum = sum + a[n];31 32             }33             ave = 1.0 * sum / a.Length;34             Console.WriteLine("球员总成绩是"+sum+",平均成绩是"+ave+"");35 36             int max = 0,min=200;37             int maxSub = -1, minSub = -1;38             for (int b = 0; b < a.Length;b++ )39             {40                 max = max > a[b] ? max : a[b];41                 maxSub = b;42             }43             for (int c = 0; c < a.Length; c++)44             {45                 if(min>a[c])46                 {47                     min=a[c];48                     minSub=c;49                 }50             }51             Console.WriteLine((maxSub+1)+"球员中最高成绩是" + max + ","+(minSub+1)+"最差成绩是"+min+"");52 53 54         }55     }56 }

做一个36选7的彩票生成器。

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace ConsoleApplication1 7 { 8     class Class3 9     {10         static void Main(string[] args)11         {12             int[] a = new int[7];13 14             Random rand = new Random();15             for (int i = 0; i < a.Length; i++)//7-代表要生成7个不同的数16             {17                 //生成一个随机数18                 int n = rand.Next(36);19                 n++;20 21                 //查重22                 bool chong = false;23                 for (int j = 0; j < a.Length;j++ )24                 {25                     if (n==a[j])26                     {27                         chong = true;28                         break;29                     }30                 }//for31                 //确定n合不合理32                 if (chong == false)33                 {34                     a[i] = n;35                 }36                 else37                 {38                     i--;39                 }40             }//for41 42             //显示彩票号43             for (int k = 0; k < a.Length;k++ )44             {45                 Console.Write(a[k]+"\t");46             }47         }//Main48     }49 }

20个手机号 滚动显示,随机抽取一个中奖号码

 

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace ConsoleApplication1 7 { 8     class Class5 9     {10         //20个手机号码滚动显示,随机抽出一个中奖号码11         static void Main(string[] args)12         {13             string[] a=new string [20];14             Random rand = new Random();15 16             //输入20个电话号码17             for(int b=0;b<a.Length;b++)18             {19                 Console.Write("请输入第"+(b+1)+"几个电话号码:");20                 a[b] = Console.ReadLine();21              22             }23 24             for (int c = 0; c < a.Length;c++ )25             {26                 Console.WriteLine(""+(c+1)+"个电话号码是:"+a[c]+"");27             }28 29             //随机抽取一个并输出30             for (int d = 0; d < a.Length;d++ )31             {32                 System.Threading.Thread.Sleep(500);33                 int e = rand.Next(20);34                 Console.Clear();35                36                 Console.WriteLine(a[d]);37             }38 39 40         }41     }42 }

 

作业1226