实验2

#include <stdio.h>
int main()
{
    char colour;

    while (scanf("%c", &colour) != EOF) {
        if (colour >= 'a' && colour <= 'z') {
            if (colour == 'r') {
                printf("stop!\n");
            }
            else if (colour == 'y') {
                printf("wait a minute\n");
            }
            else if (colour == 'g') {
                printf("go go go\n");
            }
            else {
                printf("something must be wrong...\n");
            }
        }
    }

    return 0;
}

 


#include <stdio.h>

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


int main()
{
int day;
srand(time(0));


day = rand() % 30;


int chance;
int guess;


printf("猜猜2023年11月哪一天会是你的lucky day,你有三次机会:");


for (chance = 3; chance > 0; chance--) {
scanf("%d", &guess);
if (guess == day) {
printf("right!\n");
return 0;
}
else if (guess > day) {
printf("too late!\n");
}
else if (guess < day) {
printf("too early!\n");
}


if (chance == 1) {
printf("\n");
printf("次数用完了,告诉你,11月,你的lucky day是%d号", day);
}
else {
printf("再猜:");
}
}


return 0;
}

 

 

posted @ 2023-10-16 17:34  吕江楠  阅读(18)  评论(0)    收藏  举报