Use of Switch Case in C


Levels of difficulty: / perform operation:

C program to ask the user to enter a number. If the number is 1 print “One”, if the number is 2 print “Two”, if the number is 3 print “Three”, otherwise print “Other than One, Two or Three.

C Program

  
#include <conio.h>
#include <stdio.h>
void main()
{
	int i;
	clrscr();
	printf("\nENTER A NUMBER: ");
	scanf("%d",&i);
	switch(i)
{
		case 1:
			printf("\nNUMBER IS ONE");
			break;
		case 2:
			printf("\nNUMBER IS TWO");
			break;
		case 3:
			printf("\nNUMBER IS THREE");
			break;
		default:
printf("\nNUMBER IS OTHER THAN ONE, TWO OR THREE");
	}
	getch();
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview