Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Switch in Decision Statements of Programming in C
2242 Views
Switch 
Switch case is used to compare one variable value with multiple values. Checking the case values one by one. If Case value is equals then its block of statement will execute. All the conditions are not equals to case values then the default block of statements will get executed.
Syntax 
Switch (value)
{
case 1:
   statements;
   break;
case 2:
   statements;
   break;
case 3:
   statements;
   break;


default:
   statements;
   break;
}
Program
#include
void main(){
    int num;
    printf("Enter a number 1 to 3");
    scanf("%d",&num);
    switch(num){
        case 1:
        printf("One");
        break;
        case 2:
        printf("Two");
        break;
        case 3:
        printf("Three");
        break;
        default:
        printf("Invalid number");
        break;
    }
}
Output 
Enter a number
2

Two
Next Topics
Next lessons of current book.
Decision Statements of Programming in C
Looping Statements of Programming in C
Looping Statements of Programming in C
Looping Statements of Programming in C
Looping Statements of Programming in C
Previous Topics
Previous lessons of current book.
Decision Statements of Programming in C
Decision Statements of Programming in C
Decision Statements of Programming in C
Decision Statements of Programming in C
Input Output Functions of Programming in C
Best Lessons of "Programming in C"
Top lessons which are viewed more times.
Structures and Unions of Programming in C
Input Output Functions of Programming in C
Structures and Unions of Programming in C
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details