10個の整数を入力し、最小の数を最初の数に置き換えます.


10個の整数を入力し、最小の数を最初の数に置き換え、最大の数を最後の数に置き換えます.3つの関数を書きます:1.10個の数2を入力、処理を行う.10個の数を出力します.
 

  
  
  
  
  1. #include <iostream>  
  2. #include<cmath>  
  3. #include<iomanip>  
  4. #include<string>  
  5. using namespace std;  
  6.  
  7.  
  8. int main()  
  9. {    
  10.  void shuru(int *);  
  11.  void swap(int *);  
  12.  void shuqu(int *);  
  13.  int a[10];  
  14.  
  15.  
  16.  shuru(a);  
  17.  swap(a);  
  18.  shuqu(a);  
  19.  return 0;  
  20. }  
  21.  
  22. void shuru(int *p1)  
  23. {    
  24.  cout<<" 10 :"<<endl;  
  25.  int i;  
  26.  for(i=0;i<10;i++)  
  27.   cin>>*(p1+i);  
  28.  cout<<endl;  
  29.  
  30. }  
  31. void swap(int *number)  
  32. {  
  33.  int *max,*min,*p,temp,b;  
  34.  
  35.  max=min=number;  
  36.  
  37.  for (p=number+1;p<number+10;p++)  
  38.   if (*p>*max) max=p; //max  
  39.     // [9] *max ( )*max [0] [9]             
  40.  temp=number[9];number[9]=*max;*max=temp;  
  41.  
  42.  for (p=number+1;p<number+10;p++)  
  43.   if (*p<*min) min=p;  
  44.  
  45.  temp=number[0];number[0]=*min;*min=temp;  
  46.  
  47.  
  48. }  
  49.  
  50.  
  51. void shuqu(int *number)  
  52. {     
  53.  int *p;  
  54.  
  55.  for(p=number;p<number+10;p++)  
  56.   cout<<*p<<" ";  
  57.  
  58.  cout<<endl;  
  59. }