数组

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 数组
{
    class Program
    {
        static void Main(string[] args)
        {
            ////float[] score; //声明了一个数组,就是告诉你有一列火车,叫什么
            //////数组类型怕【】数组名;
            //////数组名=数组类型【】
            ////score = new float[30];//数组的长度为30就是告诉我们数组的长度是数组元素的个数
            ////float[]score=new float[30];
            //int n = 10;
            //int[] array = new int[n];//注意数组的长度一定是整数可以是常量也可以是变量
            //array[0] = 5;//说明第一个数的赋值是5,所以最后一个数的中括号里的值是长度减一
            //int n1 = array.Length;//求数组的长度
            //Console.WriteLine(n1);
            ////跟循环配套用
            //int i;int sum=0;
            //Console.WriteLine("请输入10个数");
            //for (i = 0; i <= n1 - 1; i++)
            //{
            //    array[i] = Convert.ToInt32(Console.ReadLine());
            //     sum = sum + array[i];
            //}
            double[] score = new double[10];
            double sum = 0;
            Console.WriteLine("请输入10个学生的成绩");
            for (int i = 0; i <= score.Length - 1; i++)
            {
                score[i] = Convert.ToDouble(Console.ReadLine());
                
                sum = sum + score[i];
                
            } Console.WriteLine("学生的平均成绩为"+sum/10);
            int num = 0;
            for(int i= 0;i<= score.Length-1;i++)
            {
                if (score[i] > sum / 10)
                {
                    num++; 
                }
            } Console.WriteLine("高于平均分的人有{0}个",num);
        }
    }
}

 

posted @ 2024-04-09 19:17  困到很想醒  阅读(3)  评论(0编辑  收藏  举报