fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #include <stdlib.h>
  6.  
  7. #include <time.h>
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. int a[10],b[10],max,t;
  14.  
  15. cout<<"原始数组为:"<<endl;
  16.  
  17. srand((unsigned)time(NULL));
  18.  
  19. for(int i=0;i<10;i++)
  20.  
  21. {
  22.  
  23. a[i]=rand()%100;
  24.  
  25. cout<<a[i]<<" ";
  26.  
  27. }
  28.  
  29. cout<<endl;
  30.  
  31. cout<<"调整后的结果:"<<endl;
  32.  
  33. for(int j=0;j<9;j++)
  34.  
  35. {
  36.  
  37. for(int k=0;k<9-j;k++)
  38.  
  39. {
  40.  
  41. if(a[k]>a[k+1])
  42.  
  43. {
  44.  
  45. t=a[k];
  46.  
  47. a[k]=a[k+1];
  48.  
  49. a[k+1]=t;
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57. for(int l=0;l<10;l++)
  58.  
  59. {
  60.  
  61. cout<<a[l]<<" ";
  62.  
  63. }
  64.  
  65. return 0;
  66.  
  67. }
  68.  
  69.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
原始数组为:
23   33   63   10   5   1   19   65   42   73   
调整后的结果:
1   5   10   19   23   33   42   63   65   73