C LANGUAGE - Nested switch case

// Nested switch case example #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int choice,ch1,ch2; clrscr(); printf("\n1.Pen \n2.Fruits"); printf("\nEnter your choice:>>"); scanf("%d",&choice); switch(choice) { case 1: { printf("\n1.Micro \n2.Renold \n3.Cello:"); printf("\nEnter your choice:>>\n"); scanf("%d",&ch1); switch(ch1) { case 1: { printf("\nMicro"); break; } case 2: { printf("\nRenold"); break; } case 3: { printf("\nCello"); break; } default: { printf("Invalid case"); } } break; } case 2: { printf("\n1.Mango \n2.Orange \n3.Pineple"); printf("Enter your choice:>>\n"); scanf("%d",&ch2); switch(ch2) { case 1: { printf("\nMango"); break; } case 2: { printf("\nOrange"); break; } case 3: { printf("\nPineple"); break; } default: { printf("Invalid case"); } } break; } default: { printf("Invalid Choice"); } } getch(); }
Note: Click on copy button to copy the given code and you can paste it in any online compiler to see the result, IF YOU ARE A MOBILE USER THEN DOWNLOAD "CODING C" (Free App) COMPILER FROM GOOGLE PLAY STORE.