as

Wednesday 12 November 2014

Switch Statement in C


Switch case statements are used in scenarios where there are multiple flows depending upon the condition.
Depending upon the switch expression, specific case block is executed. Switch expression is evaluated as a constant value.

Below program demonstrates the use of switch statement in C.

#include<stdio.h>
void main()
{
  int n;
  printf("Enter choice");
  scanf("%d",&n);

  switch (n)
  {
    case 1:
           printf("One");
         break;
    case 2:
          printf ("Two");
          break;
    case 3:
          printf ("Three");
          break;
    case 4:
          printf ("Four");
          break;
    case 5:
          printf ("Five");
          break;
    default:
         printf ("invalid value ");
         break;
   }
 getchar();

}







No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis