C Program switch case: "Multi-cases Example" with output
#include <stdio.h>
int main() { int choice; printf("Choose an option (1-4):\n"); printf("1. Print 'One'\n"); printf("2. Print 'Two'\n"); printf("3. Print 'Three'\n"); printf("4. Print 'Four'\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("You chose 'One'\n"); break; case 2: printf("You chose 'Two'\n"); break; case 3: printf("You chose 'Three'\n"); break; case 4: printf("You chose 'Four'\n"); break; default: printf("Invalid choice. Please select an option from 1 to 4.\n"); } return 0; }Choose an option (1-4):
1. Print 'One'
2. Print 'Two'
3. Print 'Three'
4. Print 'Four'
Enter your choice: 5
Invalid choice. Please select an option from 1 to 4.
Comments
Post a Comment