题解 | #获取数组最值#
获取数组最值
https://www.nowcoder.com/practice/53d110f6cdd14f21af285698f975b59c
#include <iostream> using namespace std; int main() { int arr[6] = { 0 }; int len = sizeof(arr) / sizeof(int); for (int i = 0; i < len; i++) { cin >> arr[i]; } // write your code here...... int max=arr[0],min=arr[0];//先设置最大值和最小值都为第一个值 for(int i=1;i<len;i++){ if(max<arr[i]){ max=arr[i]; } if(min>arr[i]){ min=arr[i]; } } cout<<min<<' '<<max<<endl; return 0; }