Home > Article > Backend Development > Nested switch case in C language
Write a C program that uses a nested switch case to check whether the password entered by the user is valid based on the user's ID.
The solution is as follows-
In C language, we can write the internal switch and place it in the external switch .
The case values of internal and external switches can have the same value.
The following C program uses a nested switch case to check whether the password entered by the user is valid based on the user's ID-
Live Demonstration
#include <stdio.h> int main(){ int userid; int pwd; printf("enter userid:"); scanf("%d",&userid); switch (userid){ case 1234: printf("enter password:"); scanf("%d", & pwd); switch (pwd){ case 0000: printf("Tutorials Point"); break; default: printf("incorrect password"); break; } break; default: printf("incorrect userid"); break; } }
You will see the following output -
Run 1:enter userid: 1234 enter password: 0000 Tutorials Point Run 2: enter userid: 1234 enter password: 234 incorrect password
The above is the detailed content of Nested switch case in C language. For more information, please follow other related articles on the PHP Chinese website!