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

后端 未结 5 1709
春和景丽
春和景丽 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:42

    You are initializing min to 0.

    Try following

    int min = Int32.MaxValue;
    

    Also In case you are accepting negative values as input, you should initialize max to minimum integer value.

    int max = Int32.MinValue;
    

提交回复
热议问题