当前位置:编程学习 > asp >>

.net机试题总结

1、下面是一个由*号组成的4行倒三角形图案。要求:1、输入倒三角形的行数,行数的取值3-21之间,对于非法的行数,要求抛出提示“非法行数!”;2、在屏幕上打印这个指定了行数的倒三角形。

*******

*****

***

*

  static void Main(string[] args)

        {

            while (true)

            {

                Console.Write("请输入行数:范围3-21,输入0退出程序。");

                int line = 0;

                if (!Int32.TryParse(Console.ReadLine(), out line))

                {

                    Console.WriteLine("请输入正确的行数!");

                    continue;

                }

                if (line == 0)

                {

                    Console.WriteLine("退出!");

                    break;

                }

                else if (!(line > 2 && line < 22))

                {

                    Console.WriteLine("非法行数!请输入正确的行数!");

                    continue;

                }

                for (int i = 0; i < line; i++)

                {

                    int j = 0;

                    for (; j < i; j++)

                    {

                        Console.Write(" ");

                    }

                    for (int k = j; k < line; k++)

                    {

                        Console.Write("* ");

                    }

                    Console.WriteLine();

                }

            }

        }


2、现有1~100共一百个自然数,已随机放入一个有98个元素的数组a[98]。要求写出一个尽量简单的方案,找出没有被放入数组的那2个数,并在屏幕上打印这2个数。注意:程序不用实现自然数随机放入数组的过程。

  static void Main(string[] args)

        {

            while (true)

            {

                int[] arry = new int[98];

                Random rd = new Random();

                List<int> temp = new List<int>();

                //随机产生98个1-100自然数

                while (temp.Count < 98)

                {

                    int result = rd.Next(1, 101);//随机产生1~100随机数;

                    if (temp.Contains(result))

                    {

                        continue;

                    }

                    temp.Add(result);

                }

                //将98个数填充到数组中;

                for (int i = 0; i < 98; i++)

                {

                    arry[i] = temp[i];

                }


                ///*强烈推荐这种做法开始*/

                ////标识为1

                int[] arrytemp = new int[101];

                for (int i = 0; i < 98; i++)

                {

       &n

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,