[問題]大樂透電腦選號問題
看板C_and_CPP (C/C++)作者totoron10 (totoron)時間14年前 (2011/07/29 16:11)推噓3(3推 0噓 13→)留言16則, 8人參與討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
習題:請撰寫一程式來隨機產生6個號碼(1-49)
----------------------------------------
以下是程式碼:
#include <stdio.h>
#include <stdlib.h>
#define randomize() srand((unsigned) time(NULL))
#define random(x) (rand() % (x))
int main
{
int loto[6],count=0,i;
int flag;
randomize();
while(count<6){
flag=0;
loto[count]=random(49)+1;
for(i=0;i<=count;i++)
if(loto[count]==loto[i])
flag=1;
if(flag!=0)
count++;
}
for(i=0;i<count;i++)
printf("\n第%d 個樂透號碼:%d",i+1,loto[i]);
printf("\n")
system("PAUSE");
return 0;
}
--------------------------------------------------------------------
1.想請問一下當中flag在程式中的用意是?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.125.87
推
07/29 16:13, , 1F
07/29 16:13, 1F
→
07/29 16:13, , 2F
07/29 16:13, 2F
→
07/29 16:15, , 3F
07/29 16:15, 3F
→
07/29 16:56, , 4F
07/29 16:56, 4F
→
07/29 16:57, , 5F
07/29 16:57, 5F
→
07/29 16:57, , 6F
07/29 16:57, 6F
→
07/29 16:58, , 7F
07/29 16:58, 7F
→
07/29 18:58, , 8F
07/29 18:58, 8F
→
07/29 20:28, , 9F
07/29 20:28, 9F
→
07/29 20:31, , 10F
07/29 20:31, 10F
→
07/29 20:31, , 11F
07/29 20:31, 11F
→
07/29 21:10, , 12F
07/29 21:10, 12F
→
07/29 21:15, , 13F
07/29 21:15, 13F
推
07/29 21:17, , 14F
07/29 21:17, 14F
→
07/29 21:19, , 15F
07/29 21:19, 15F
推
07/29 21:45, , 16F
07/29 21:45, 16F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章