zoukankan      html  css  js  c++  java
  • 2.27

    一维数组
    int [] array = new int [5]{1,2,3,4,5};
     int [] array = new int[5];
     array[0] = 1;
     array[1] = 2;
     array[2] = 3;
     array[3] = 4;
     array[4] = 5;
     array[5] = 6; 超出索引范围

     int a = array[2];string [] ss = new string[3];

    ss[0] = "1";
    ss[1] = "2";
    ss[2] = "3";

    string b = ss[2];

    输入三个人名放入数组
    string[] name = new string[3];
    Console.Write("请输入第一个人名:");
    name[0] = Console.ReadLine();
    Console.Write("请输入第二个人名:");
    name[1] = Console.ReadLine();
    Console.Write("请输入第三个人名:");
    name[2] = Console.ReadLine();
    for (int i = 1; i <= 3; i++)
    {
    Console.Write("请输入第{0}个人名:",i);
    name[i - 1] = Console.ReadLine();
    }

    //根据班级人数创建一个数组,要求每个人的姓名都要放进去
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    string[] name = new string[n];
    for (int i = 0; i < n; i++)
    {
    Console.Write("请输入第{0}个人的姓名:", i + 1);
    name[i] = Console.ReadLine();
    }
    Console.WriteLine("所有人员姓名输入完毕,请按回车键查看所有人员姓名!");
    Console.ReadLine();
    Console.WriteLine();
    for (int i = 0; i < n; i++)
    {
    Console.Write(name[i] + " ");
    }
    Console.ReadLine();


    从控制台输入班级人数
    将每个人的年龄放入数组,
    将所有人的年龄求总和
    求平均年龄
    求年龄最大
    Console.Write("请输入班级人数:");
    int n = int.Parse(Console.ReadLine());
    int [] age = new int[n];
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
    Console.Write("请输入第{0}个人的年龄:",i+1);
    age[i] = int.Parse(Console.ReadLine());
    sum+=age[i];
    }
    Console.WriteLine(sum);
    Console.WriteLine(sum/n);
    int agemax = 0;
    for (int i = 0; i < n; i++)
    {
    if (agemax < age[i])
    {
    agemax = age[i];
    }
    }
    Console.WriteLine("最大年龄是:"+agemax);

    //冒泡排序
    for (int i = 0; i < n; i++)
    {
    for (int j = i; j < n-1; j++)
    {
    if (age[i] < age[j+1])
    {
    int zhong = age[i];
    age[i] = age[j+1];
    age[j+1] = zhong;
    }
    }
    }

    for (int i = 0; i < n; i++)
    {
    Console.WriteLine(age[i]);
    }
    Console.ReadLine();


    //输入班级人数
    //输入每个人的分数
    //求总分、平均分、两个最高分,两个最低分
    Console.Write("请输入班级的人数");
    int n = int.Parse(Console.ReadLine());
    double[] b = new double[n];
    double fen = 0;
    for (int i = 0; i < n; i++)
    {
    Console.Write("请输入{0}的分数:", i + 1);
    b[i] = double.Parse(Console.ReadLine());
    fen += b[i];
    }
    Console.Write(fen);
    Console.Write(fen/n);


    Console.ReadLine();

  • 相关阅读:
    2019-4-16-C#-使用反射获取私有属性的方法
    2019-5-21-C#-命令行如何静默调用-del-删除文件
    2019-6-14-WPF-shows-that-some-windows-in-multithreading-will-be-locked-in-the-PenThreadWorker-constr...
    2019-9-11-完整的-P2P-应用需要包含哪些功能
    2019-3-1-VisualStudio-扩展开发-获得输出窗口内容
    2018-10-19-C#-序列类为-xml-可以使用的特性大全
    2018-8-10-win10-uwp-手把手教你使用-asp-dotnet-core-做-cs-程序
    2018-10-31-win10-uwp-使用-asp-dotnet-core-做图床服务器客户端
    2018-8-10-docfx-做一个和微软一样的文档平台
    linux分区方案
  • 原文地址:https://www.cnblogs.com/power8023/p/5712765.html
Copyright © 2011-2022 走看看