找出陣列中的最大值

#C#

Posted by Phyxsius on 2023-09-16

internal class Program
{
    private static void Main(string[] args)
    {
        int[] ary = { 1, 2, 7, 3, 4};

        int max = 0;

        for(int i=0; i<ary.Length; i++)
        {
            if(i==0)
            {
                max = ary[i];
            }
            else
            {
                if (ary[i] > max)
                {
                    max = ary[i];
                }
            }
        }

        Console.WriteLine("陣列內容:");
        showArray(ary);

        Console.WriteLine("陣列最大值為:" + max);
    }

    //顯示陣列內容
    static void showArray(int[] ary)
    {
        for (int i=0; i<ary.Length; i++)
        {
            Console.Write(ary[i] + ",");
        }
        Console.WriteLine();
    }
}

#C#







Related Posts

利用react-bootstrap打造React風格頁面

利用react-bootstrap打造React風格頁面

DAY31:Greed is Good

DAY31:Greed is Good

Python 101 快速入門教學

Python 101 快速入門教學


Comments