您的位置:首页 > 其它

指针寻找最大小值

2015-09-20 21:21 183 查看
#include<iostream>
using namespace std;
void max_min(int a[], int n, int* max, int*min)
{
	int*p;
	*max = *min = *a;
	for (p = a + 1; p < a + n; p++)
	{
		if (*p > *max)
			*max = *p;
		else if (*p < *min)
			*min = *p;

	}
}
int main()
{
	int i, a[10];
	int max, min;
	cout << "输入十个数字" << endl;
	for (int i = 0; i < 10; i++)
		cin >> a[i];
	max_min(a, 10, &max, &min);
	cout << "输出数组" << endl;
	for (int j = 0; j < 10; j++)
		cout << a[j] << endl;
	system("pause");
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: