logo

More details about the switch statement in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int fruit = 2; printf("What fruit would you like? "); scanf("%d", &fruit); switch (fruit) { case 0: printf("You selected apples\n"); break; case 1: case 2: printf("You selected oranges or lemons\n"); break; default: printf("No such fruit\n"); break; } return 0; }
Course thumb

The C programming language made simple