0607
/******************* 0505_game.c
隨機產生一整數[1-6] 存入陣列 a[] 印出陣列
****************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int n=6,i=1, a[6],dice[6],right=0,total=0;
unsigned seed;
seed = (unsigned)time(NULL); // 取得時間序列
srand(seed); // 以時間序列當亂數種子
printf("正修科大 0024 林進益\n");
printf("\n請輸入6個1~6的整數: ");
for(i=1;i<=6;i++)
{
scanf("%d",&dice[i]);
}
total=0;
do
{
right=0;
i=1;
total++;
printf("\n total= %d \n",total);
do
{
a[i]= rand() % 6 + 1;
if(a[i] == dice[i])
right++;
printf("a[ %d ] = %d dice[ %d ] = %d \n",i,a[i],i,dice[i]);
i++;
}while (i<=n);
if(right > 0)
{
printf("\n 您猜中 %d 個\n",right);
}
else
{
printf("\n 歹勢! 您摃龜了\n",right);
}
}while (right < 6);
system("pause");
return 0;
}