我用C++寫的,你可以參考一下
#include <iostream>using namespace std;void max_min(int int_arr[], int *min, int *max) { *min = int_arr[0]; //假設最小數是陣列下標0的值 *max = int_arr[0]; //假設最大數是陣列下標0的值 for (int i=0; i<3; i++) { if (int_arr[i] < *min) *min = int_arr[i]; if (int_arr[i] > *max) *max = int_arr[i]; }}int main(){ int a[3]; cout << "請依次輸入三個整數" << endl; cin >> a[0]; cin >> a[1]; cin >> a[2]; int min, max; max_min(a, &min, &max); cout << "最小整數:" << min << endl; cout << "最大整數:" << max << endl; system("pause"); return 0;}
我用C++寫的,你可以參考一下
#include <iostream>using namespace std;void max_min(int int_arr[], int *min, int *max) { *min = int_arr[0]; //假設最小數是陣列下標0的值 *max = int_arr[0]; //假設最大數是陣列下標0的值 for (int i=0; i<3; i++) { if (int_arr[i] < *min) *min = int_arr[i]; if (int_arr[i] > *max) *max = int_arr[i]; }}int main(){ int a[3]; cout << "請依次輸入三個整數" << endl; cin >> a[0]; cin >> a[1]; cin >> a[2]; int min, max; max_min(a, &min, &max); cout << "最小整數:" << min << endl; cout << "最大整數:" << max << endl; system("pause"); return 0;}