答案仅供参考。
练习 1-1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int no;
int ans;
int temp;
srand(time(NULL));
printf("输入1--开始抽签,输入其它数--退出抽签:");
do {
printf("你的选择是?");
scanf("%d", &no);
if (no != 1)
break;
temp = rand()%7;
printf("此次你抽到的数是%d。\n",temp);
switch(temp) {
case 0 : puts("你抽到了大吉。"); break;
case 1 : puts("你抽到了中吉。"); break;
case 2 : puts("你抽到了小吉。"); break;
case 3 : puts("你抽到了未知。"); break;
case 4 : puts("你抽到了大凶。"); break;
case 5 : puts("你抽到了中凶。"); break;
case 6 : puts("你抽到了小凶。"); break;
}
} while (no == 1);
return 0;
}
练习 1-2
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int no;
int ans;
int temp;
srand(time(N