#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("enter the value of n");
scanf("%d",&n);
switch(n)
{
case1:printf("monday");
break;
case2:printf("tueday");
break;
case3:printf("wednesday");
break;
case4:printf("thursday");
break;
case5:printf("friday");
break;
case6:printf("saturday");
break;
case7:printf("sunday");
break;
default:printf("invalid number");
}
}
If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).
Default clause in switch statement used to indicate that the desired option is not available with the switch case statement. it is similar to else statement of if statement which is used when the condition does not satisfy.
There is no "elseif" statement in C. You can only use "else" and "if" separately. This is a good reason for switch/case/break.
using break; statement
There are two programming languages which use a C switch statement. The two languages are C and C++, hence the name C switch statement. There may be more, but those are the most obvious ones
Case is used to label each branch in the switch statement in Java Program
If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).
we can use switch statement in multiple time but in if statement we can not use multiple time
If statement is single selection statement,whereas the switch statement is multiple selective.
crossbar switch
Single-pole, double-throw. The switch directs a single input to two possible outputs.
Disadvantages are : 1.The crossbar switch is singled-layered switch. 2.At each point,there is a switch when closed,connects one of the inputs to one of the outputs.
Default clause in switch statement used to indicate that the desired option is not available with the switch case statement. it is similar to else statement of if statement which is used when the condition does not satisfy.
This question cannot be generally answered, the output depends on the actual program.
A component switch also known as a matrix switch enables users to switch between multiple video inputs to multiple LCD's, TV's or projectors with compatible outputs.
prog1: #include<stdio.h> int main() { switch(1) { int i=0; case 1:printf("%d",i); } getchar(); return 0; } Output: garbage value. prog2: #include<stdio.h> int main() { switch(1) { printf("Inside Switch"); case 1:printf("Case 1\n"); } printf("Outside Switch"); getchar(); return 0; } Output: Case 1 Outside Switch. The statements before a case labelled statement seem unreachable according to program 2 but then why don't i get an error for an undeclared variable i in the first program (only a warning). Would be really helpful if someone could explain in detail that how the switch statement is treated internally.
In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:switch (variableName){case condition1; command1;case condition2; command2;...}