Jun 19, 2020

C program to check password is correct or incorrect using switch-case

Ex: write a C program to check password is correct or incorrect using switch-case. How to write a C program to check given password is correct or incorrect using switch-case. C program to check password is correct or incorrect using switch-case.

Input from user:

Enter your password: 1010

Expected output:

Welcome



Quick links:





Step by step logic of the given program:

1. Accept input (password) from user declare varible say ps.

2. Switch the value of ps using switch(ps).

3. There is 1 possible value of ps(1010).

4. Therefore write 1 case inside the switch.

5. If  case does not match then for default case print incorrect password. 





Program:

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

printf("Enter your password: ");
scanf("%d",&ps);

switch(ps)
{
case 1010:
printf("--WELCOME--");
break;

default:
printf("-INCORRECT PASSWORD-");
}
return 0;
}



Above program shows the following output:



Share This:    Facebook Twitter

0 comments:

Post a Comment

If you have any doubts, please discuss here...