返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int x;
  8.     srand(time(NULL));
  9.     int a[10];
  10.     for(int i=0; i<=9; i++)
  11.     {
  12.         re:
  13.         a[i]=rand()%38+1;
  14.         for(int j=0; j<i; j++)
  15.         {
  16.             if(a[i]==a[j])
  17.             {
  18.                 goto re;
  19.             }
  20.         }
  21.     }
  22.     cout<<"排序前: ";
  23.     for(int i=0; i<=9; i++)
  24.     {
  25.         cout<<a[i]<<" ";
  26.     }

  27.     for(int i=0; i<=9; i++)
  28.     {
  29.         for(int j=0; j<=9; j++)
  30.         {
  31.             if(a[i]>a[j])
  32.             {
  33.                 x=a[j];
  34.                 a[j]=a[i];
  35.                 a[i]=x;
  36.             }
  37.         }

  38.     }
  39.     cout<<endl<<"排序後: ";
  40.     for(int i=0; i<=9; i++)
  41.     {
  42.         cout<<a[i]<<" ";
  43.     }

  44. }
複製代碼

TOP

返回列表