C Switch

C Switch Statement tests the value of a given variable or expression against a no. of statements and when a match is found, a block of statement associated with that case is executed. or we can say that it is a alternative of if-else statement.

Syntax  :-

Switch(Expression)
{

case 1:
block 1;
break;

case 2:
block 2;
break;

Default :
block n;
break;
}

  C Program to check a character is vowel or consonant using C switch statment

#include<stdio.h>

#include<conio.h>

void main()
{

char ch;
printf("\n Enter a Character");

scanf("%c",&ch);

switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
{

printf("\n The Character is vowel ");
break;

default;
printf("\n Character is consonant");

}

getch();
}

 

 

 






Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top