c语言程序设计:剪刀、石头和布游戏
原件:
编写了TC2.0和gcc。
/*=======================================================
*作者:wacs5
*日期:20100601(年月日)
*功能:剪刀、石头和布
*=======================================================*/
# include & ltstdio.h & gt
# include & ltconio.h & gt
# include & ltstdlib.h & gt
# include & lttime.h & gt
int main()
{
char name[4][15]={ " ","剪刀","石头","布" };
int x[2];
int I;
srand(time(NULL));
for(I = 0;我& lt10;i++) /*10次游戏*/
{
x[0]= 1+rand()% 3;/*生成一个从1到3的数字*/
x[1]= 1+rand()% 3;/*生成另一个从1到3的数字*/
printf(" A = %-12sB = %-12s \ t ",name[x[0]],name[x[1]]);
if (x[0]==x[1])
printf(" draw \ n ");/*和*/
else if(x[0]% 3+1 = = x[1])/* lost */
printf(" lost \ n ");
else /*win*/
printf(" win \ n ");
}
getch();
返回0;
}