#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
/*
n为需比较的个数;
*p为数组指针;
*/
double maxNum(int n,double *p){
cout <<n<<endl;
double result = 0.0;
if(n>256){
cout <<"error"<<endl;
return -1;
}
else{
//将数组第一个值赋给result;
result = *p;
int i = 1;
while(i < n){
cout<<"i:"<<i<<endl;
//result与下一个数进行比较,大的数赋给result
if(result < *(p+1)){
result = *(p+1);
}
p+=1;
i++;
}
}
cout <<"result:"<<result<<endl;
return 0;
}
double minNum(int m,double *p){
cout <<m<<endl;
double minresult = 0.0;
if(m>256){
cout <<"error"<<endl;
return -1;
}
else{
minresult = *p;
int i = 1;
while(i < m){
if(minresult > *(p+1)){
minresult = *(p+1);
}
p+=1;
i++;
}
}
cout <<"minresult:"<<minresult<<endl;
return 0;
}
int main() {
double *p = new double[256]{7,2,3,16,5,24};
maxNum(6,p);
minNum(6,p);
return 0;
}