C language: Simulate Password Input three times.
Simulate Password Input three times. Solution: Program:
# Include <stdio. h> # include <windows. h> # include <string. h> int main () {int I; char * p = "123456"; char arr [10]; for (I = 0; I <3; I ++) {printf ("Enter Password:"); scanf ("% s", arr); if (strcmp (p, arr) = 0) {break ;} else {printf ("Incorrect password! \ N ") ;}}if (I = 3) {printf (" three times wrong password input, the system will automatically close in 3 seconds! \ N "); Sleep (3000);} else if (I <3) {printf (" Congratulations! \ N ") ;}return 0 ;}
Result 1: The password 123567 is incorrect! Enter Password: 65848 incorrect password! Enter Password: 135268 incorrect password! The password entered three times is incorrect. The system will automatically shut down 3 seconds later! Press any key to continue... result 2: Enter Password: 123456. Congratulations, your logon is successful! Press any key to continue...