c#查找数组中最大的数字索引

问题描述 投票:-2回答:1

i被要求在10的数组中找到最大的数字,然后是它的索引。首先,我已经设法使用“ for”循环来找到数组中的最大数字(我们还没有使用任何函数,而是“ Math”),但是我很难获取其索引。]

example:
the array: 1,55,1,7,9,10,1,3,8,10
result:
biggest numbers:55
its index:1 (if we count from 0)

到目前为止我的代码:

int[] numbers = new int[10];
        int max = 0;
        int count;

        for(count=0;count<numbers.Length;count++)
        {
            numbers[count] = int.Parse(Console.ReadLine());
        }

        for (count = 0; count < numbers.Length; count++)
        {
            numbers[0] = max;

            if(numbers[count] > max)
            {
                max = numbers[count];
            }

        }

        Console.WriteLine("the biggest number is" + max);
c# arrays for-loop
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.