西安网站建设全包,本地wordpress密码忘记了,wordpress底部制作,免费制作二级网站题干
本题要求实现一个函数#xff0c;找出数组中一部分数据的最大值和最小值。 题目保证没有无效数据。
函数接口定义#xff1a; void sublistMaxMin ( int* from, int* to, int* max, int* min ); 其中 from和to都是用户传入的参数#xff0c;分别存放数组部分数据的起…题干
本题要求实现一个函数找出数组中一部分数据的最大值和最小值。 题目保证没有无效数据。
函数接口定义 void sublistMaxMin ( int* from, int* to, int* max, int* min ); 其中 from和to都是用户传入的参数分别存放数组部分数据的起始地址和结束地址,并且fromto。 其中max和min为用户传入的地址分别用于在sublistMaxMin中保存from至to对应区段中数组元素的最大值和最小值的地址。
裁判测试程序样例
#include stdio.h
void sublistMaxMin ( int* from, int* to, int* max, int* min );
int main()
{int list[1000];int len0;int from, to, max, min;scanf(%d, len);int i;for(i0; ilen; i){scanf(%d, list[i]);}scanf(%d%d, from, to);sublistMaxMin(listfrom, listto, max, min);printf(list[%d-%d]: max %d, min %d\n, from, to, max, min);return 0;
}/* 请在这里填写答案 */输入样例 5 1 2 3 4 5 0 4 输出样例 list[0-4]: max 5, min 1
解答过程
void sublistMaxMin(int* from, int* to, int* max, int* min) {*max *from;*min *from;for (int* ptr from 1; ptr to; ptr) {if (*ptr *max) {*max *ptr;}if (*ptr *min) {*min *ptr;}}
}