谁能帮我写一下这个掷筛子的C语言程序

来源:百度知道 编辑:UC知道 时间:2024/09/24 17:08:39
Make a program to simulate the throwing of a dice.

Input a number (integer); accept only numbers in the range 1 to 6.

Example, with 5 as input:
line1: X X
line2: X
line3: X X

Finally print in a loop in sequence the patterns of line 1, 2 and 3.
The choice of the proper stringconstant for a particular line is determined by the entered number; thus line2 will give the same pattern on entering a 3 and/or a 5.

#include<stdio.h>
void main()
{
int num = 0;
char dice[6][3][4] = {{" "," * "," "}, {"* "," "," *"},
{"* "," * "," *"}, {"* *"," ","* *"}, {"* *"," * ","* *"}, {"* *","* *","* *"}};
printf("Input a number(1 to 6):");
scanf("%d", &num);
if ((num < 1)||(num > 6))
{
printf("Wrong input!\n");
return;
}
printf("%s\n", dice[num-1][0]);
printf("%s\n", dice[num-1][1]);
printf("%s\n", dice[num-1][2]);
}

其实这个应该不难的。你做个格式输出的子函数,再做个“随机数”产生函数,再做一个显示频率跳变的,也就是延时时间长短问题。