编写一个C#程序,要求从键盘输入10个数存放在数组中,分别求出最大数和最小数存放在第一第二个元素里

这篇博客介绍了如何使用C#编写程序,从键盘读取10个数字并存储在数组中。通过两种不同的方法,一种在主函数内实现,另一种通过调用其他成员函数,分别找出数组中的最大值和最小值,并将它们存放在数组的第一和第二个元素。程序二利用函数分离,提高了代码的可读性和避免错误。
摘要由CSDN通过智能技术生成

程序一(在主函数中实现):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[10];
            for (int i = 0; i < a.Length; i++)
                a[i] = int.Parse(Console.ReadLine());

            for (int i = 0; i < a.Length; i++)
            {
                if (a[0] < a[i]) a[0] = a[i];
                if (a[0] > a[i]) a[1] = a[i];

            }
            Console.WriteLine("最大值是:{0}", a[0]);
            Console.WriteLine("最小值是:{0}", a[1]);
        }
    }
}

程序二(调用其他函数):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
    class Program
    {
        public void qiuji
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值