※ 引述《Asurda (戀愛Y世代重播囉)》之銘言:
: ans[0]=rand()%10; //以下是一個數一個數地檢查,讓四個數字不能重複
: do {
: ans[1]=rand()%10;
: }while (ans[0]==ans[1]);
: do {
: ans[2]=rand()%10;
: }while (ans[0]==ans[2] || ans[1]==ans[2]);
: do {
: ans[3]=rand()%10;
: }while (ans[0]==ans[3] || ans[1]==ans[3] || ans[2]==ans[3]);
ans[0]=rand()%10;
for (int i=1,j=0;i<=3;i++)
while (j<i)
if((ans[i]=rand()%10)!=ans[j])
j++;
簡單吧﹍﹍﹍
這是用兩個迴圈的﹍﹍
還有一個迴圈就做得出來的喔!!
--
給我記著!
I'm a member of
CKEISC 16th | National Taiwan University
Department of Networking | Department of Naval Architecture
| and Ocean Engineering
twwang@ck.tp.edu.tw | twwang@linux.na.ntu.edu.tw
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: IP075.dialup.nt