Switch Case Statement Example Program In C Programming Language

Definition

In c programming language, switch statement is a type of selection mechanism used to allow block code among many alternatives.

Simply,It changes the control flow of program execution via a mutliple block. we can use for Nested if.. else statement.

Syntax:

switch ( <variable> ) {
	case value1:
	 //Block 1 Code Here
	 break;

	case value2:
	 //Block 1 Code Here
	 break;
	...

	default:
	 Code to execute for not match case
	 break;
}

Example Program For Switch

/* Example Program For Switch Case In C Programming Language
  little drops @ thiyagaraaj.com
  Coded By:THIYAGARAAJ MP       */

// Header Files
#include<stdio.h>
#include<conio.h>

//Main Function
int main()
{
  // Variable Declaration
  char ch;

  //Get Input Value
  printf("Enter the Vowel (In Capital Letter):");
  scanf("%c",&ch);

  //Switch Case Check
  switch( ch )
  {
    case 'A' : printf( "Your Character Is A\n" );
         break;

    case 'E' : printf( "Your Character Is E\n" );
         break;

    case 'I' : printf( "Your Character Is I\n" );
         break;

    case 'O' : printf( "Your Character Is O\n" );
         break;

    case 'U' : printf( "Your Character Is U\n" );
         break;

    default : printf( "Your Character is Not Vowel.Otherwise Not a Capital Letter\n" );
         break;
  }
  // Wait For Output Screen
  getch();

  //Main Function return Statement
  return 0;
}

Sample Output:

Enter the Vowel (In Capital Letter):A
Your Character Is A

Enter the Vowel (In Capital Letter):O
Your Character Is O


Enter the Vowel (In Capital Letter):h
Your Character is Not Vowel.Or Not a Capital Letter

 

Top Pages