C#小练习ⅳ

已知10个学生的英语成绩为80,90,67,89,78,85,45,69,77,95

求:统计优良中差各分数段的人数和所占百分比。

假设优(90-100),良(80-89),中(60-79),差(0-59)

 

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
 
namespaceConsoleApplication1
{
    class Program
    {
        static void Main(string[]args)
        {
            float A=0, B=0, C=0, D=0;
            int[] a=new int[10];
            Random greate = new Random();
            for (int i = 0; i < a.Length;i++)
                     {
                      a[i]=greate.Next(101);
                     }
            for (int i = 0; i < a.Length;i++)
            {
                if(a[i]<=100&&a[i]>=90)
                {
                    A++;
                }
                else if (a[i] <= 89&& a[i] >=80)
                {
                    B++;
                }
                else if (a[i] <= 79&& a[i] >= 60)
                {
                    C++;
                }
                else
                {
                    D++;
                }
 
                Console.Write(a[i]+"");
            }
            Console.WriteLine("\n优:{0}百分比{1}%\n良:{2}百分比:{3}%\n中:{4}百分比:{5}%\n差:{6}百分比:{7}%\n",A,A/10,B,B/10,C,C/10,D,D/10);
           
        }
    }
}


 

 

已知10个学生的身高为156,150,167,178,180,176,173,154,155,158

求:平均身高、最高身高、最低身高,并统计高于平均身高的人数

 

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
 
namespace_2
{
    class Program
    {
        static void Main(string[]args)
        {
            float[] a = new float[10];
            float sum = 0;
            float max=0, min=200, average=0,num = 0;
            Random greate = new Random();
            for (int i = 0; i < a.Length;i++)
            {
                a[i] = greate.Next(130, 200);
               Console.Write("{0,4}",a[i]);
            }
            for (int i = 0; i < a.Length;i++)
            {
                sum += a[i];
                if (a[i]>max)
                {
                    max = a[i];
                }
                if (min>a[i])
                {
                    min = a[i];
                }
            }
         
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i]>sum/10)
                {
                    num++;
                }
            }
            Console.WriteLine("\n平均身高:{0}\n最高身高:{1}\n最低身高:{2}\n高于平均身高人数:{3}\n",sum/10,max,min,num);
 
        }
    }
}


 

 

设计程序,产生10个10-19的随机数,对它们递增排序并输出结果。

 

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
 
namespace_3
{
    class Program
    {
        static void Main(string[]args)
        {
            int[] a = new int[10];
            Random greate = new Random();
            for (int i = 0; i < a.Length;i++)
            {
                a[i] = greate.Next(10, 20);
            }
            System.Array.Sort(a);
            for (int i = 0; i < a.Length;i++)
            {
               Console.Write("{0,3}",a[i]);
            }
           
        }
    }
}


 

 

创建并初始化以下类型的数组:

int[][,]

int[][ ][ ]

将以上数组的元素打印出来

 

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
 
namespacearray
{
    class Program
    {
        static void Main(string[]args)
        {//int[ ][,]int[ ][ ][ ]
 
            int[][,] a = new int[2][,];
            {
                a[0] = new int[4, 3] {
                { 4, 2, 3 },
                { 4, 2, 3 },
                { 4, 2, 3 },
                { 4, 2, 3 } };
                a[1] = new int[3, 2] {
                { 4, 2 },
                { 2, 3 },
                { 2, 3 } };
            }
            for (int i = 0; i < a.Length;i++)
            {
                for (int j = 0; j <a[i].GetLength(0); j++)
                {
                    for (int k = 0; k <a[i].GetLength(1); k++)
                    {
                        Console.Write(a[i][j,k] + " ");
                    }
                }
 
            }
 
            int[][][] b = new int[3][][]
            {
                               new int[][] {
                                   new int[] {1, 2 }
                               },
                               new int[][] {
                                   new int[] {1, 2, 3 }
                               },
                               new int[][] {
                                   new int[] {1 }
                               }
            };
            Console.WriteLine();
            for (int q = 0; q < b.Length;q++)
            {
                for (int p = 0; p <b[q].Length; p++)
                {
                    for (int m = 0; m <b[q][p].Length; m++)
                    {
                       Console.Write(b[q][p][m] + " ");
                    }
 
                }
            }
        }
    }
}

 

 

版权说明

著作权归作者所有©。 
商业转载请联系作者获得授权,非商业转载请注明出处。 
本文作者:Joe.Smith

发表日期:2016年10月16日 
本文链接:http://blog.csdn.net/qq_26816591/article/details/52828963

来源:CSDN 
更多内容:C#小练习ⅲ

编译运行环境:visual studio 2010


posted @ 2016-10-16 09:10  Joe.Smith  阅读(425)  评论(0编辑  收藏  举报