LMS知識社群各系上網率圖資處首頁登入
樂透彩
by 郭怡勝 2017-11-21 11:14:35, 回應(0), 人氣(274)



/*
隨機產生7個整數[1-10] 
****************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int   a, b,c,d,e,f,g,i ;
int a1[10],x[10];
 a1[1]=100;
 a1[2]=200;
 a1[3]=400;
 a1[4]=800;
 a1[5]=1600;
 a1[6]=10000;
 a1[7]=300000; 
unsigned seed;
seed = (unsigned)time(NULL); // 取得時間序列
srand(seed); // 以時間序列當亂數種子 
printf("正修科大 40404113 郭怡勝\n");  
a = rand() % 10 + 1 ;
do
 b = rand() % 10 + 1 ;
 c = rand() % 10 + 1 ;
 d = rand() % 10 + 1 ;
 e = rand() % 10 + 1 ;
 f = rand() % 10 + 1 ;
 g = rand() % 10 + 1 ;
// printf("電腦產生 %d %d %d %d %d %d %d\n",a,b,c,d,e,f,g);
}while ( b%2 ==0 || c%2 ==0 || d%2 ==0 || e%2 ==0 || f%2 ==0 || g%2 ==0 ) ;
printf("\n\n");
printf("電腦產生 %7d %7d %7d %7d %7d %7d %7d\n",a,b,c,d,e,f,g);
for(i=1;i<=7;i++)
x[i]= rand() % 7 +1;
printf("對應獎金 %7d %7d %7d %7d %7d %7d %7d\n",a1[x[1]],a1[x[2]],a1[x[3]],a1[x[4]],a1[x[5]],a1[x[6]],a1[x[7]]);
if (a%2==0)
printf("\n恭喜您! 中了%d個鈺晟的微笑!\n",a1[x[1]]);
else
printf("\n可惜你沒得到鈺晟的微笑...\n");

system("pause");   
}
附件: