Q.)WAP to check password is correct or incorrect using switch-case in C program.
#include< stdio.h>
int main()
{
int ps;
printf("Enter your password: ");
scanf("%d",&ps);
switch(ps)
{
case 2000:
printf("--WELCOME--");
break;
default:
printf("-INCORRECT PASSWORD-");
}
getch();
}
Output
Enter your password: 2000
--WELCOME--
Program Explanation
Step 1 : Include header files (#include< stdio.h> and #include< conio.h>).
Step 2 : Start with main function with return type.
Step 3 : parenthesis to start and end the program { }.
Step 4 : declare variables with data type i.e, 'ch' is an integer type so we use "char" data type.
Step 5 : Use output function printf() to print the output on the screen.
Step 6 : Use input function scanf() to get input from the user.
Step 7 : here, we have check password is correct or incorrect using switch case, Enter your password: . we can enter 2000. it was go to case 2000. then the statement was right. then print "--welcome--". otherwish , print "-INCORRECT PASSWORD-"
Step 8 : using getch() function to hold the screen.