随机数产生的函数: arc4random_uniform(m); //产生小于m的随机数,从0开始
代码:
- <font face="宋体"> //定义变量并接受用户输入
- int num,computer;
- //提示
- printf("输入你的拳:石头-0,剪刀1,布2\n");
- //系统产生0-2的随机数
- computer = arc4random_uniform(3);
- printf("系统出的数:%d\n",computer);
- scanf("%d",&num);
- //判断
- if (num < 0 || num > 2){
- printf("请按套路出牌\n");
- return 0;
- } else if (num ==0 && computer == 1
- || num == 1 && computer == 2
- || num == 2 && computer == 0) {
- printf("好吧,你赢了!\n");
- } else if (computer ==0 && num == 1
- || computer == 1 && num == 2
- || computer == 2 && num == 0)
- printf("别玩儿了,你妈喊你回家吃饭\n");
- else
- {
- printf("平局\n");
- }
- return 0;
- </font>
复制代码
|