【C++】输入10个整数,将其中最小的数与第一个数对换【原创技术】
(2012-05-22 08:51:39)
标签:
c整数对换it |
分类: C加加开发 |
题目:
输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。
源代码:
输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。
源代码:
- //课程:C++实验3
- //题目:输入10个数,最小数与第一个交换,最大数与最后一个交换
- //语言:C++
- //作者:武叶
- //创作时间:2012年3月20日#include
<iostream>
- #include<cmath>
- #include<iomanip>
- #include<string>
- using namespace std; void input(int
*p1)
- {
- cout<<"请输入10个整数:"<<endl;
- int i;
- for(i=0;i<10;i++)
- cin>>*(p1+i);
- cout<<endl;
- }
- void max_min_value(int
*number)
- {
- int
*max,*min,*p,temp,b;
- max=min=number;
- for
(p=number+1;p<number+10;p++)
- if
(*p>*max)
- max=p;
//max存入最大数的内存地址
- temp=number[9];
- number[9]=*max;
- *max=temp;
- for
(p=number+1;p<number+10;p++)
- if
(*p<*min)
- min=p;
- temp=number[0];
- number[0]=*min;
- *min=temp;
- } void output(int
*number)
- {
- int *p;
- for(p=number;p<number+10;p++)
- cout<<*p<<"
";
- cout<<endl;
- }
- int main()
- { int a[10];
- input(a);
- max_min_value(a);
- output(a);
- return 0;
- }
更多详细内容::::去学习

加载中…