網頁

2009年5月12日 星期二

產生 亂數

產生10個0~99的亂數存在a[10] 中

66 則留言:

  1. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[1000];
        srand((unsigned)time(NULL));
        int i =rand();
        cout<<i<<endl;
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }

    回覆刪除
  2. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    unsigned starttime=clock();
    int num,i;
    srand((unsigned)time(NULL));
    for (i=0;i<10;i++)
    {
    num=rand()%100+1;
    printf("%d\n",num);
    }
    system ("pause");
    return 0;
    }

    回覆刪除
  3. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
      
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }

    回覆刪除
  4. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }

    輸出:a[0]=55
    a[1]=12
    a[2]=89
    a[3]=83
    a[4]=44
    a[5]=46
    a[6]=50
    a[7]=98
    a[8]=13
    a[9]=83
    a[10]=39
    CPU time:0sec

    回覆刪除
  5. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  6. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  7. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }
    答案
    a[0]=96
    a[1]=41
    a[2]=92
    a[3]=99
    a[4]=84
    a[5]=66
    a[6]=76
    a[7]=77
    a[8]=46
    a[9]=44
    a[10]=74
    CPU time:0sec
    請按任意鍵繼續 . . .

    回覆刪除
  8. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  9. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  10. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }


    答案
    a[0]=58
    a[1]=74
    a[2]=33
    a[3]=69
    a[4]=66
    a[5]=73
    a[6]=98
    a[7]=11
    a[8]=26
    a[9]=53
    a[10]=64
    CPU time:0sec
    請按任意鍵繼續 . . .

    回覆刪除
  11. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  12. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  13. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=0 ;n<=10 ;n++)
    {
    i[n]=rand()%99+1;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  14. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
      
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }
    a[0]=0
    a[1]=53
    a[2]=83
    a[3]=79
    a[4]=27
    a[5]=24
    a[6]=7
    a[7]=1
    a[8]=50
    a[9]=44
    a[10]=88
    CPU time:0sec

    回覆刪除
  15. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }
    執行:
    a[0]=22
    a[1]=84
    a[2]=44
    a[3]=37
    a[4]=67
    a[5]=0
    a[6]=29
    a[7]=55
    a[8]=38
    a[9]=26
    a[10]=63
    CPU time:0sec
    請按任意鍵繼續 . . .

    回覆刪除
  16. #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[100];
        srand((unsigned)time(0));
        for (int x=0;x<100;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  17. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int i[10],n;
        srand(time(0));
        for (n=0 ;n<=10 ;n++)
        {
            i[n]=rand()%99+1;
            printf("i[%d]=%d\n",n,i[n]);
        }
       
        system("pause");
        return 0;
    }

    回覆刪除
  18. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  19. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int i[10],n;
        srand(time(0));
        for (n=0 ;n<=10 ;n++)
        {
            i[n]=rand()%99+1;
            printf("i[%d]=%d\n",n,i[n]);
        }
       
        system("pause");
        return 0;
    }

    回覆刪除
  20. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int i[10],n;
        srand(time(0));
        for (n=0 ;n<=10 ;n++)
        {
            i[n]=rand()%99+1;
            printf("i[%d]=%d\n",n,i[n]);
        }
       
        system("pause");
        return 0;
    }

    回覆刪除
  21. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  22. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  23. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  24. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  25. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int i[10],n;
        srand(time(0));
        for (n=0 ;n<=10 ;n++)
        {
            i[n]=rand()%99+1;
            printf("i[%d]=%d\n",n,i[n]);
        }
       
        system("pause");
        return 0;
    }

    回覆刪除
  26. #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(0));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  27. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  28. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    int i[10],n;
    srand(time(0));
    for (n=1 ;n<=10 ;n++)
    {
    i[n]=rand()%100;
    printf("i[%d]=%d\n",n,i[n]);
    }

    system("pause");
    return 0;
    }

    回覆刪除
  29. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  30. #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    int main()
    {
         unsigned starttime=clock();
         int num,i;
         srand((unsigned)time(NULL));
         for (i=0;i<10;i++)
         {
             num=rand()%100;
             printf("%d\n",num);
             }
             system("pause");
             return 0;
             }
     

    回覆刪除
  31. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  32. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  33. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  34. #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(0));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  35. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  36. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  37. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned staettime=clock();
    int a[10],i;
    srand(( unsigned )time(NULL));
    //int i=rand();
    cout<<i<<endl;
    for(int x=0;x<10;x++)
    {
    a[x]=rand()%99+1;
    //cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    for(int x=0;x<10;x++)
    {
    cout<<a[x]<<endl;
    }
    /*usinged enddtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl*/
    system("pause");
    return 0;
    }

    回覆刪除
  38. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned staettime=clock();
    int a[10],i;
    srand(( unsigned )time(NULL));
    //int i=rand();
    cout<<i<<endl;
    for(int x=0;x<10;x++)
    {
    a[x]=rand()%99+1;
    //cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    for(int x=0;x<10;x++)
    {
    cout<<a[x]<<endl;
    }
    /*usinged enddtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl*/
    system("pause");
    return 0;
    }

    回覆刪除
  39. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned staettime=clock();
    int a[10],i;
    srand(( unsigned )time(NULL));
    //int i=rand();
    cout<<i<<endl;
    for(int x=0;x<10;x++)
    {
    a[x]=rand()%99+1;
    //cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    for(int x=0;x<10;x++)
    {
    cout<<a[x]<<endl;
    }
    /*usinged enddtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl*/
    system("pause");
    return 0;
    }

    回覆刪除
  40. #include<iostream>
    #include<cstdlib>
    using namespace std;
    int main()
    {
         int a[10];
        srand((unsigned)time(NULL));
        int i=rand();
        for(int x=0;x<10;x++)
        {
                a[x]=rand()%100;
                cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("pause");
        return 0;
    }
     

    回覆刪除
  41. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned staettime=clock();
    int a[10],i;
    srand(( unsigned )time(NULL));
    //int i=rand();
    cout<<i<<endl;
    for(int x=0;x<10;x++)
    {
    a[x]=rand()%99+1;
    //cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    for(int x=0;x<10;x++)
    {
    cout<<a[x]<<endl;
    }
    /*usinged enddtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl*/
    system("pause");
    return 0;
    }

    回覆刪除
  42. #include <iostream>
    #include <cstdlib>
    using  namespace std;
    int main()
    {
        int a[10];
        srand ((unsigned)time(0));
        int i=rand();
        for(int x=0;x<10;x++)
       {
         a[x]=rand()%100;
         cout<<"a["<<x<<"]="<<a[x]<<endl;
       }
      system("pause");
      return 0;
    }

    回覆刪除
  43. #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    int a[10];
    srand((unsigned)time(0));
    int i =rand();
    for (int x=0;x<10;x++)
    {
    a[x]=rand()%100;
    cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    system("PAUSE");
    return 0;
    }




    結果
    a[0]=28
    a[1]=39
    a[2]=49
    a[3]=34
    a[4]=72
    a[5]=83
    a[6]=80
    a[7]=31
    a[8]=62
    a[9]=31
    請按任意鍵繼續 .

    回覆刪除
  44. #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    int a[10];
    srand((unsigned)time(0));
    int i =rand();
    for (int x=0;x<10;x++)
    {
    a[x]=rand()%100;
    cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  45. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
       int a[10];
       int i;
       srand((unsigned)time(NULL));
       for(i=0; i<10; i++)
       {
        a[i]=rand() % 100;
       }
       for(i=0; i<10; i++)
       {
        cout<<a[i]<<endl;
       }
     system("PAUSE");
     return 0;
    }
    --------------------
    ans:
    57
    4
    90
    98
    44
    50
    11
    58
    85
    6

    回覆刪除
  46. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  47. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  48. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  49. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  50. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  51. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  52. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main(){
    int a[10];
    srand((unsigned)time(NULL));
    for (int i=0;i<10;i++)
    {
    a[i]=rand()%100;
    }
    for (int w=1;w<10;w++)
    printf("%d\n",a[w]);
    system("pause");
    return 0;
    }

    回覆刪除
  53. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int main(){
       int a[10];
       srand((unsigned)time(NULL));
       for (int i=0;i<10;i++)
       {
           a[i]=rand()%100;
    }
    for (int w=1;w<10;w++)
    printf("%d\n",a[w]);

    system("pause");
    return 0;
    }

    回覆刪除
  54. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int a[10];
        int i;
        srand((unsigned)time(NULL));
        for(i=0;i<10;i++)
        {
         a[i]=rand()%100;
         }
         for(i=0;i<10;i++)
         {
          cout<<a[i]<<endl;
          }
          system ("pause");
          return 0;
    }

    回覆刪除
  55. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        int a[10];
        int i;
        srand((unsigned)time(NULL));
        for(i=0;i<10;i++)
        {
         a[i]=rand()%100;
         }
         for(i=0;i<10;i++)
         {
          cout<<a[i]<<endl;
          }
          system ("pause");
          return 0;
    }

    回覆刪除
  56. #include<iostream.h>
    #include<stdlib.h>
    #include<time.h>
    int main()
    {
        int a[10];
        int i;
        srand((unsigned)time(NULL));
        for(i=0;i<10;i++)
        {
                         a[i]=rand()%100;
                         }
                         for(i=0;i<10;i++)
                         {
                                          cout<<a[i]<<endl;
                                          }
                                          system("pause");
                                          return 0;
                                          }

    回覆刪除
  57. #include<iostream.h>
    #include<stdlib.h>
    #include<time.h>
    int main()
    {
        int a[10];
        int i;
        srand((unsigned)time(NULL));
        for(i=0;i<10;i++)
        {
                         a[i]=rand()%100;
                         }
                         for(i=0;i<10;i++)
                         {
                                          cout<<a[i]<<endl;
                                          }
                                          system("pause");
                                          return 0;
                                          }

    回覆刪除
  58. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }
    答案
    a[0]=96
    a[1]=41
    a[2]=92
    a[3]=99
    a[4]=84
    a[5]=66
    a[6]=76
    a[7]=77
    a[8]=46
    a[9]=44
    a[10]=74
    CPU time:0sec
    請按任意鍵繼續 . . .

    回覆刪除
  59. #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
      int a[10];
      int i;
      srand((unsigned)time(NULL));
      for(i=0; i<10; i++)
      {
       a[i]=rand() % 100;
      }
      for(i=0; i<10; i++)
      {
       cout<<a[i]<<endl;
      }
    system("PAUSE");
    return 0;
    }

    回覆刪除
  60. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }


    答案:
    a[0]=72
    a[1]=61
    a[2]=26
    a[3]=54
    a[4]=50
    a[5]=69
    a[6]=3
    a[7]=0
    a[8]=10
    a[9]=23
    a[10]=38
    CPU time:0.032sec

    回覆刪除
  61. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  62. #include <iostream>
    #include <ctime>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        for (int x=0;x<10;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        system("PAUSE");
        return 0;
    }

    回覆刪除
  63. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned starttime=clock();
    int a[10];
    srand((unsigned)time(NULL));
    int i =rand();

    for (int x=0;x<11;x++)
    {
    a[x]=rand()%100;
    cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    unsigned endtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl;
    system("PAUSE");
    return 0;
    }

    回覆刪除
  64. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
        unsigned starttime=clock();
        int a[10];
        srand((unsigned)time(NULL));
        int i =rand();
        for (int x=0;x<11;x++)
        {
            a[x]=rand()%100;
            cout<<"a["<<x<<"]="<<a[x]<<endl;
        }
        unsigned endtime=clock();
        cout<<"CPU time:"
            <<(double)(endtime-starttime)/CLK_TCK
            <<"sec"<<endl;
        system("PAUSE");
        return 0;
    }

    答案
    a[0]=96
    a[1]=41
    a[2]=92
    a[3]=99
    a[4]=84
    a[5]=66
    a[6]=76
    a[7]=77
    a[8]=46
    a[9]=44
    a[10]=74
    CPU time:0sec
    請按任意鍵繼續 . . .

    回覆刪除
  65. #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
    unsigned starttime=clock();
    int num,i;
    srand((unsigned)time(NULL));
    for (i=0;i<10;i++)
    {
    num=rand()%100+1;
    printf("%d\n",num);
    }
    system ("pause");
    return 0;
    }

    回覆刪除
  66. #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    unsigned starttime=clock();
    int a[1000];
    srand((unsigned)time(NULL));
    int i =rand();
    cout<<i<<endl;
    for (int x=0;x<11;x++)
    {
    a[x]=rand()%100;
    cout<<"a["<<x<<"]="<<a[x]<<endl;
    }
    unsigned endtime=clock();
    cout<<"CPU time:"
    <<(double)(endtime-starttime)/CLK_TCK
    <<"sec"<<endl;
    system("PAUSE");
    return 0;
    }

    回覆刪除

HTML 編輯器