Press "Enter" to skip to content

Switch Case In C

Phone Code Check Using C

A switch statement tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier.

Code of this program :

#include <stdio.h>
int main()
{
int phone_code;
printf("\n Enter phone code :");
scanf ("%d", &phone_code);

switch ( phone_code )
{
case 61 :
printf("\n This phone_code area is Brasilia");
break;
case 71 :
printf("\n This phone_code area is Salvador");
break;
case 11 :
printf("\n This phone_code area is Sao palo");
break;
case 21 :
printf("\n This phone_code area is Rio de janeiro");
break;
case 32 :
printf("\n This phone_code area is Juiz de fora");
break;
case 19 :
printf("\n This phone_code area is Campinas");
break;
case 27 :
printf("\n This phone_code area is Vitoria");
break;
case 31 :
printf("\n This phone_code area is Belo Horizonte");
break;
default :
printf("\n It is not any phn_code area");
break;
}
return 0;
}

After run the code result looks like :

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *