练习题:
彩票
static void Main(string[] args)
{
Random r = new Random();
int[] caipiao = new int[7];
while (true)
{
for (int i = 0; i < 6; )
{
if (i == 0)
{
caipiao[i] = r.Next(1, 34);
i++;
}
else
{
int temp = r.Next(1, 34);
for (int j = 0; j < i; )
{
if (temp == caipiao[j])
{
temp = r.Next(1, 34);
j = 0;
}
else
{
j++;
}
}
caipiao[i] = temp;
i++;
}
}
for (int i = 0; i < caipiao.Length - 1; i++)
{
for (int j = 0; j < caipiao.Length - 1; j++)
{
int temp1 = 0;
if (caipiao[i] < caipiao[j])
{
temp1 = caipiao[i];
caipiao[i] = caipiao[j];
caipiao[j] = temp1;
}
}
}
caipiao[6] = r.Next(1, 17);
for (int i = 0; i < caipiao.Length; i++)
{
if (i == 6)
{
Console.Write(“蓝球" + caipiao[i] + "\t");
}
else
{
Console.Write(caipiao[i] + "\t");
}
}
Console.WriteLine();
Console.ReadLine();
}
}
集合与特殊集合
示例:
//ArrayList al = new ArrayList();
//al.Add(3);
//al.Add(5);
//al.Add(7);
//al.Insert(1,9);
//int geshu = al.Count;
//Console.WriteLine(al[0]);
//Console.WriteLine(al[1]);
//Console.WriteLine(al[2]);
//Console.WriteLine(al[3]);
//Console.ReadLine();
//ArrayList al = new ArrayList();
//al.Add(3);
//al.Add(5);
//al.Add(7);
//al.Add(8);
//al.Insert(1,9);
//al.Remove(7);
//int geshu = al.Count;
//foreach (var item in al)
//{
// Console.WriteLine(item);
//}
//Console.ReadLine();
//ArrayList al = new ArrayList();
//al.Add(3);
//al.Add(4);
//al.Add(5);
//al.Add(6);
//al.Add(7);
//al.Insert(1,9);
//al.RemoveAt(2);
//int geshu = al.Count;
//foreach (var item in al)
//{
// Console.WriteLine(item);
//}
//Console.ReadLine();
ArrayList al = new ArrayList();
Console.WriteLine("renshu");
int a = Convert.ToInt32(Console.ReadLine());
double sum = 0;
for (int i = 0; i < a; i++)
{ Console.WriteLine("输入"+i+"个学生分数");
al.Add(Convert.ToInt32(Console.ReadLine()));
sum += Convert.ToDouble(al[i]);
}
double avg = sum / a;
Console.WriteLine("平均分是"+avg);
Console.ReadLine();