Tuesday, 19 April 2011

Switch Statements : Example program on switch statements

/*     switch statement.       */
#include < stdio.h >
 int main(void) {
  //    Local Declarations
  int printFlag = 0;

  printf("Enter an intger value: ");
  scanf(" %d", & printFlag);

  //    Program fragment to demonstrate switch
  switch (printFlag) {
   case 1:
    printf("This is case 1\n");
    break;

   case 2:
    printf("This is case 2\n");
    break;

   default:
    printf("This is default\n");
    break;
  } // switch
  return 0;
 } // main



switch statement

No comments:

Post a Comment