• 输入10个人的分数,求最高分最低分平均分及冒泡排序


     

      

     
                //输入10个人的分数,求最高分最低分平均分
                int[] fenshu = new int[10];
                int max = 0;
                int min = 0;
                int sum = 0;
                for (int i = 0; i < 10; i++)
                {
                    fenshu[i] = int.Parse(Console.ReadLine());
                    sum += fenshu[i];
    
                    if (i == 0)
                    {
                        max = fenshu[i];
                        min = fenshu[i];
                    }
                    else
                    {
                        if (max < fenshu[i])
                        {
                            max = fenshu[i];
                        }
                        if (min > fenshu[i])
                        {
                            min = fenshu[i];
                        }
                    }
                }
    
                Console.WriteLine("最大值:"+max);
                Console.WriteLine("最小值:" + min);
                Console.WriteLine("平均分:" + sum/10);
               
    
                //输入全班同学的年龄,按年龄从大到小排序
                Console.Write("请输入人数:");
                int n = int.Parse(Console.ReadLine());
    
                int[] nianling = new int[n];
                for (int i = 0; i < n; i++)
                {
                    Console.Write("请输入第{0}个人的年龄:",i+1);
                    nianling[i] = int.Parse(Console.ReadLine());
                }
    
                //开始排序
    
                for (int j = 0; j < n - 1; j++)
                {
                    for (int i = j+1; i < n; i++)
                    {
                        if (nianling[i] > nianling[j])
                        {
                            //等量代换
                            int zhong = nianling[i];
                            nianling[i] = nianling[j];
                            nianling[j] = zhong;
                        }
                    }
                }
    
    
                foreach (int i in nianling)
                {
                    Console.WriteLine(i);
                }
                    Console.ReadLine();
  • 相关阅读:
    验证码破解 | Selenium模拟登陆12306
    验证码破解 | Selenium模拟登录知乎
    Numpy | 16 算术函数
    Numpy | 15 数学函数
    Numpy | 14 字符串函数
    Numpy | 13 位运算
    Numpy | 12 数组操作
    Numpy | 11 迭代数组
    Numpy | 10 广播(Broadcast)
    Numpy | 09 高级索引
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4810483.html
Copyright © 2020-2023  润新知