Description
採用指针法,输出10个整型数中的最大值和最小值
Input
10个整数
Output
最大值和最小值
Sample Input
2 6 3 8 1 5 7 0 4 9
Sample Output
max=9
min=0
/* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名:test.cpp
* 作者:陈丹妮
* 完毕日期:2015年 6 月 1 日
* 版 本 号:v1.0
*/
#include <iostream>
using namespace std;
int main()
{
int a[10],i,max,min,*p;
p=a;
for(i=0; i<10; i++)
cin>>*p++;
max=min=a[0];
for(p=a; p<a+10; p++)
{
if(*p>max)
max=*p;
if(*p<min)
min=*p;
}
cout<<"max="<<max<<endl;
cout<<"min="<<min<<endl;
return 0;
}
学习心得:最终复习到指针了,好开心,加油加油。继续努力。!