用C#语言编写:数组分析器

 static void Main(string[] args)
        {
            #region 创建数组
            Console.Write("请输入数组的长度");
            int[] numbers = new int[int.Parse(Console.ReadLine())];
            for (int i = 0; i < numbers.Length; i++)
            {
                Console.Write("请输入数组的第" + (i + 1) + "项:");
                numbers[i] = int.Parse(Console.ReadLine());
            }
            Console.Clear();
            #endregion
            #region  对组数排序
            for (int i = 0; i < numbers.Length-1; i++)
            {
                for (int j = i+1; j < numbers.Length; j++)
                {
                    if (numbers[i] > numbers[j])
                    {
                        int temp = numbers[i];
                        numbers[i] = numbers[j];
                        numbers[j] = temp;
                    }
                    
                }
            }
            Console.WriteLine("您输入的数字排序后如下:");
            for (int i = 0; i < numbers.Length; i++)
            {
                Console.Write(numbers[i]+"\t");
            }
            Console.WriteLine();
            #endregion
            #region  找出奇数
            Console.WriteLine("其中,以下数字是奇数:");
            //查找问题
            //查找样本:数组中所有的数字
            //查找目标:样本数据除以2不为0
            //找到后的操作:输出目标数据
            for (int i = 0; i < numbers.Length; i++)
            {
                int n = numbers[i];
                if (n % 2 != 0)
                {
                    Console.Write(n + "\t");
                }
            }
            Console.WriteLine();

            #endregion
            #region  找出质数
            Console.WriteLine("以下数字式质数:");
            for (int i = 0; i < numbers.Length; i++)
            {
                int n = numbers[i];
                bool isfind = false;
                for (int j = 2; j < n; j++)
                {
                    if (n % j == 0)
                    {
                        isfind = true;
                        break;
                    }
                }
                        if(!isfind)
                        {
                        {
                            Console.Write(n+"\t");
                        }
                }
            }
            #endregion
        }

转载于:https://www.cnblogs.com/Maigo/p/8638606.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值