Skip to content

Instantly share code, notes, and snippets.

@novnan
Created December 27, 2013 11:21
Show Gist options
  • Save novnan/8145736 to your computer and use it in GitHub Desktop.
Save novnan/8145736 to your computer and use it in GitHub Desktop.
// 根据用户掷色子的值,显示相应个数的星号*
#include <stdio.h>
void showone ();
void showtwo ();
void showthree ();
void showfour ();
void showfive ();
void showsix (); // 色子数为1~6的情况分别以星号表示
int randn(); //随机摇出色子点数
char getans (); // 根据用户的输入确定是否退出程序
void blines (); // 输出回车
void main ()
{
int r;
char ans;
ans = getans ();
srand (17);
while (ans = 'y')
{
r = randn (6);
blines (2);
switch (r)
{
case 1: showone (); break;
case 2: showtwo (); break;
case 3: showthree (); break;
case 4: showfour (); break;
case 5: showfive (); break;
case 6: showsix (); break;
}
blines (2);
ans = getans ();
}
}
int randn (int n)
{
return rand () % n + 1;
}
char getans ()
{
int ans;
printf ("Throw y/n?");
ans = -1;
while (ans == -1)
{
ans = getche ();
}
return ans;
}
void blines (int n)
{
int i;
for(i = 1; i <= n; i++)
{
printf("\n");
}
}
void showone ()
{
printf("\n*\n");
}
void showtwo ()
{
printf("*\n");
printf("*\n");
}
void showthree ()
{
printf("*\n");
printf("*\n");
printf("*\n");
}
void showfour ()
{
printf("**\n");
printf("**\n");
}
void showfive ()
{
printf("**\n");
printf("*\n");
printf("**\n");
}
void showsix ()
{
int i;
for(i = 1; i <=3; i++)
{
printf("**\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment