herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
你會用C的算子sizeof?
-
XOR prefixsum CPP python解Leetcode 1829 Maximum XOR for Each Query 其實這裡考慮的是元素個數為2^maximumBit的交換群,運算子為XOR。 [Python code請進]
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
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;
}
#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;
}
#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;
}
#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
#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;
}
#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;
}
#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
請按任意鍵繼續 . . .
#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;
}
#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;
}
#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
請按任意鍵繼續 . . .
#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;
}
#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;
}
#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;
}
#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
#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
請按任意鍵繼續 . . .
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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
請按任意鍵繼續 .
#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;
}
#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
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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
請按任意鍵繼續 . . .
#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;
}
#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
#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;
}
#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;
}
#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;
}
#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
請按任意鍵繼續 . . .
#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;
}
#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;
}
張貼留言