#include "stdio.h" #include "stdlib.h" #include "time.h" //随机函数的头文件 main() { int a,game,c=1; while(c) { srand((unsigned)time(NULL)); //按照时间改变来做随机 game=rand()%4; //让电脑随机输出1、2、3 printf("你出什么? 1.布 2.锤子 3.剪刀 4.不玩了 "); scanf("%d",&a); system("cls"); if(a>3){printf("请按任意键退出!"); break;} else if(a==game)printf("平局! ") ; else if(a==1&&game==2)printf("你赢了! "); else if(a==1&&game==3)printf("你输了! "); else if(a==2&&game==1)printf("你输了! "); else if(a==2&&game==3)printf("你赢了! "); else if(a==3&&game==1)printf("你赢了! "); else if(a==3&&game==2)printf("你输了! "); switch(game) { case 1: printf("电脑出布 "); break; case 2: printf("电脑出锤子 "); break; case 3: printf("电脑出剪刀 "); break; } } }