用C语言编石头剪子布程序,要求如下

Draw a flow chart and write a game program: stone,scissors and cloth.
The computer generate a random number (1~3), 1 stand forstone, 2 stand for scissors, 3 stand for cloth.
You can input an integer number (between 1 and3) to compare with the random number. Then judge who can win. Notice pleasegive the compariso

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
    int x,y,n;
    srand(time(NULL));
    printf("imput1-3:\n");
    scanf("%d",&x);
    y=rand()%3+1;
    n = x-y;
    
    if(n == 0)
        printf("wahahah!\n");
    else if(n == -1 || n == 2)
        printf("You win\n");
    else
        printf("You lose");
    return 0;
   
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答