應(yīng)該是a[2][3]={{1,3,2},{8,0,3}} 吧
在成都網(wǎng)站制作、成都網(wǎng)站建設(shè)過程中,需要針對客戶的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計(jì)方向。成都創(chuàng)新互聯(lián)公司還需要根據(jù)客戶的需求進(jìn)行功能模塊的開發(fā)和設(shè)計(jì),包括內(nèi)容管理、前臺展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計(jì)和安全保護(hù)等功能。
#include iostream //cout函數(shù)的頭文件
#include cstdlib
#include time.h /* srand函數(shù)與rand函數(shù)的頭文件*/
using namespace std;
int main()
{
int a[2][3]={{1,3,2},{8,0,3}},x,y,z;
srand ( (unsigned) time (NULL) );
x=rand()%2; //調(diào)用隨哪沖機(jī)函數(shù)
y=rand()%3; //調(diào)用隨機(jī)函數(shù)
z=a[x][y];
coutz"\n";
system ("pause");
return 0;
}
三樓,請注意素質(zhì)...
那是我的版權(quán)!!
樓主,一定要注意先來后到!
我咐脊本是2樓的,后因稍作修改,衡緩滲沒想到3樓抄襲我。。。
源程序代碼以及算法解釋如下:
產(chǎn)生1-10隨機(jī)數(shù)程序:
#include iostream
#include time.h
using namespace std;
int main()
{
const int n = 10;//定義隨機(jī)數(shù)個(gè)數(shù)
int number[n] = { NULL };//定義隨機(jī)數(shù)存儲的數(shù)組伍舉兄
srand((unsigned)time(NULL));//初始化隨機(jī)函數(shù)
number[0] = rand() % n;//第一個(gè)隨機(jī)數(shù)無需比較
cout number[0] " ";
for (int i = 1; i n; i++)//其余隨機(jī)數(shù)循環(huán)產(chǎn)生
{
int j = 0;
number[i] = rand() % n;//產(chǎn)生隨機(jī)數(shù)
while (1)
{
if (number[i] == number[j])//若有相同則繼續(xù)循環(huán)重新安排隨機(jī)數(shù)
{
number[i] = rand() % n;//產(chǎn)生隨機(jī)數(shù)
j = 0;//若遇到相同的就從頭遍歷
continue;
}
if (j == (i - 1))//若遍歷完就跳出
break;
j++;
}
cout number[i] " ";
}
cout endl;
return 0;
}
程序運(yùn)行結(jié)果如下:
擴(kuò)展資料:腔襲
利用vector進(jìn)行隨機(jī)數(shù)輸出:
#include iostream
#include vector
#include time.h
using namespace std;
int main()
{
const int n = 10;
int randnum;
vectorint number;
for (int i = 0; i n; i++)
{
number.push_back(i + 1);????//從尾部添加元素
cout number[i] " ";
}
cout endl;
srand((unsigned)time(NULL));
for (int j = 0; j n; j++)?????//其余隨機(jī)數(shù)答蔽循環(huán)產(chǎn)生
{
randnum = rand() % (n - j);????//rand函數(shù)生成的隨機(jī)數(shù)是0-(n-1)
cout number.at(randnum) " ";
number.erase(number.begin() + randnum);
}
cout endl;
return 0;
}
假設(shè)要生成的隨機(jī)數(shù)是大于等于20且小于等于100的整數(shù)
#includestdio.h
#includetime.h
#includestdlib.h
void?main()?畝含{?int?a,b,x;
a=20;?b=100;
srand((unsigned?int)time(NULL));?//用當(dāng)前時(shí)間生成一者耐判個(gè)隨機(jī)數(shù)種子首改
x=rand()%(b-a+1)+a;
printf("得到一個(gè)隨機(jī)數(shù):%d\n",x);
}
網(wǎng)頁題目:c語言隨機(jī)函數(shù)的代碼 c語言隨機(jī)函數(shù)srand
鏈接地址:http://www.chinadenli.net/article40/ddpideo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站營銷、網(wǎng)站收錄、Google、動態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)