Find minimum and maximum number from array, minimum is always 0

后端 未结 5 1669
春和景丽
春和景丽 2021-01-12 06:26

The program first asks the user for the number of elements to be stored in the array, then asks for the numbers.

This is my code

    static void Main         


        
5条回答
  •  迷失自我
    2021-01-12 06:37

            for (int i = 0; i < vector.GetLength(0); i++)
            {
                if (i == 0)
                {
                    VectorMinMax[1]= vector[i];
                    VectorMinMax[0]= vector[i];
                }
                else {
                    if (VectorMinMax[1] > vector[i]) VectorMinMax[1] = vector[i];
                    if (VectorMinMax[0] < vector[i]) VectorMinMax[0] = vector[i];
                }
    
            }
    

提交回复
热议问题