herrDeng網內搜尋

自訂搜尋

Ads

2009年5月12日 星期二

產生 亂數

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

66 則留言:

b9433003 提到...

#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;
}

B9733175 提到...

#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;
}

b9733129 提到...

#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;
}

B9733165 提到...

#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

B9733149 提到...

#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;
}

B9733137 提到...

#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;
}

b9733142 提到...

#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
請按任意鍵繼續 . . .

B9733138 提到...

#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;
}

B9733132 提到...

#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;
}

b9733140 提到...

#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
請按任意鍵繼續 . . .

B9733147 提到...

#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;
}

B9733128 提到...

#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;
}

B9733124 提到...

#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;
}

b9733129 提到...

#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

B9733130 提到...

#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
請按任意鍵繼續 . . .

B9733133 提到...

#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;
}

B9633174 提到...

#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;
}

b9733131 提到...

#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;
}

B9633173 提到...

#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;
}

B9633156 提到...

#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;
}

b9733146 提到...

#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;
}

b9733148 提到...

#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;
}

b9733179 提到...

#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;
}

b9633029 提到...

#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;
}

B9633139 提到...

#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;
}

B9733133 提到...

#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;
}

B9733134 提到...

#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;
}

b9733150 提到...

#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;
}

B9733135 提到...

#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;
}

B9733151 提到...

#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;
         }
 

b9733159 提到...

#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;
}

b9733143 提到...

#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;
}

b9733183 提到...

#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;
}

B9733125 提到...

#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;
}

B9733171 提到...

#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;
}

b9733152 提到...

#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;
}

B9733 提到...

#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;
}

b9733123 提到...

#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;
}

b9733161 提到...

#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;
}

b9733173 提到...

#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;
}
 

b9733163 提到...

#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;
}

b9733168 提到...

#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;
}

b9733126 提到...

#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
請按任意鍵繼續 .

b9733170 提到...

#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;
}

B9733141 提到...

#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

b9733144 提到...

#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;
}

b9733145 提到...

#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;
}

b9733166 提到...

#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;
}

B9733188 提到...

#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;
}

B9733127 提到...

#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;
}

B9733166 提到...

#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;
}

b9533182 提到...

#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;
}

b9533185 提到...

#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;
}

B9733174 提到...

#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;
}

B9733181 提到...

#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;
}

B9733136 提到...

#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;
                                      }

B9733139 提到...

#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;
                                      }

b9733157 提到...

#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
請按任意鍵繼續 . . .

b9733127 提到...

#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;
}

B9733176 提到...

#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

b9733182 提到...

#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;
}

b9733172 提到...

#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;
}

B9733156 提到...

#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;
}

B9733153 提到...

#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
請按任意鍵繼續 . . .

B9733178 提到...

#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;
}

b9733162 提到...

#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;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章