1 Binary search / Half find
2 Password login
int main()
{
int i =0;
char password[20] = "";
// Assume the password is "123456"
for (i = 0; i < 3; i++)
{
printf(" Please enter the password :>");
scanf("%s", password);
if (strcmp(password, "123456") == 0)
{
printf(" Login successful \n");
break;
}
else
{
printf(" Password error \n");
}
}
if (i == 3)
{
printf(" Roll out procedure \n");
}
return 0;
}
3 Figure guessing game
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("*****************************\n");
printf("********** 1.play *********\n");
printf("********** 0.exit *********\n");
printf("*****************************\n");
}
void game()
{
int guess = 0;
// Guess the process of the number game
// Generate random number
int r = rand() % 100 + 1;
while (1)
{// Guess the number
printf(" Guess the number :>");
scanf_s("%d", &guess);
if (guess < r)
{
printf(" Guess it's too small \n");
}
else if (guess > r)
{
printf(" Guess big \n");
}
else
{
printf(" Congratulations , You guessed right \n");
break;
}
}
}
int main()
{
int input = 0;
srand((unsinged int)time(NULL));
do
{
menu();
printf(" Please select :>");
scanf_s("%d", &input);
switch (input)
{
case 1:
printf(" Guess the number \n");
break;
case 0:
printf(" Exit the game \n");
break;
default:
printf(" Selection error \n");
break;
}
} while (input);
return 0;
}
Technology