Guess numbers games
Randomness by algorithm is actually pseudorandom
game()
menu menu
input
Generating method of random number
rand()
The timestamp gets the time on the computer at runtime
%100 The number of is 0-100
The generation of random numbers cannot be put into a loop , Because I don't know the size of every guess. It's always random
// Figure guessing game //1. The computer randomly generates a number (1~100) //2. Players guess numbers // Players guess it's too small , I told you that I guess it was too small // Players guess too much , I told you that I guessed big //
Until you get it right //3. The game can be played all the time #include<stdlib.h> #include<time.h> #include<stdio.h>
//RAND_MAX //rand Function returns a range of random values (0-32767) void menu() {
printf("*******************\n"); printf("****** 1.play *****\n");
printf("****** 0.exit *****\n"); printf("*******************\n"); } void game()
{ int guess = 0; // Generate a random number int ret = rand() % 100 + 1; //printf("%d\n", ret);
// Guess the number while (1) { printf(" Guess the number :\n"); scanf("%d", &guess); if (guess < ret) {
printf(" Guess it's too small \n"); } else if (guess > ret) { printf(" Guess big \n"); } else {
printf(" congratulations , You guessed right \n"); break; } } } int main() { int input = 0; srand((unsigned
int)time(NULL)); do { menu(); printf(" Please select :"); scanf("%d", &input); switch
(input) { case 1: game(); break; case 0: printf(" Exit the game \n"); break; default:
printf(" Selection error , Reselect !\n"); break; } } while (input); return 0; } //int main() //{
// // time_t t = time(NULL); // time_t t; // time(&t); // return 0; //}
Shutdown Sequence !
// As long as the program runs , The computer will shut down in a minute // If input : I am a pig , Just cancel the shutdown #include<stdlib.h> #include<string.h>
#include<stdio.h> int main() { char input[20] = {0}; system("shutdow -s -t
60"); //system Is a library function , Used to execute system commands printf(" Please note that , Your computer shuts down in one minute , If input : I am a pig , Just cancel the shutdown \n");
scanf("%s",input); // judge if(strcmp(input," I am a pig ")==0) { system("shutdown
-a");// shutdown -a } else { goto again; } return 0; } //while loop #include<stdlib.h>
#include<string.h> #include<stdio.h> int main() { char input[20] = {0};
system("shutdow -s -t 60"); while(1) {
printf(" Please note that , Your computer shuts down in one minute , If input : I am a pig , Just cancel the shutdown \n"); scanf("%s",input);
if(strcmp(input," I am a pig ")==0) { system("shutdown -a");// shutdown -a break; } } return 0; }
Technology