10個の整数を入力し、最小の数を最初の数に置き換えます.
10個の整数を入力し、最小の数を最初の数に置き換え、最大の数を最後の数に置き換えます.3つの関数を書きます:1.10個の数2を入力、処理を行う.10個の数を出力します.
- #include <iostream>
- #include<cmath>
- #include<iomanip>
- #include<string>
- using namespace std;
-
-
- int main()
- {
- void shuru(int *);
- void swap(int *);
- void shuqu(int *);
- int a[10];
-
-
- shuru(a);
- swap(a);
- shuqu(a);
- return 0;
- }
-
- void shuru(int *p1)
- {
- cout<<" 10 :"<<endl;
- int i;
- for(i=0;i<10;i++)
- cin>>*(p1+i);
- cout<<endl;
-
- }
- void swap(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
- // [9] *max ( )*max [0] [9]
- 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 shuqu(int *number)
- {
- int *p;
-
- for(p=number;p<number+10;p++)
- cout<<*p<<" ";
-
- cout<<endl;
- }