program
#include
#include
#include
void main()
{
int a,b,ans,ch;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
printf("1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4. exit");
printf("enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
ans=a+b;
printf("\nAfter Addition:%d",ans);
break;
case 2:
ans=a-b;
printf("\nAfter Subtraction:%d",ans);
break;
case 3:
ans=a*b;
printf("\nAfter Multiplication:%d",ans);
break;
case 4:
exit(0);
break;
}
getch();
}
If you must evaluate two or more expressions separately, use multiple if statements. If you only need to test all the possible evaluations of a single expression, use a switch.
I really think this is not possible.
In the general subject of computer programming neither switch nor transistor exist as concepts. They are out of scope.The language C (and its relatives) have a switch statement, but still no concept of transistor.The switch statement of C is a statement in the general class of multiple way decision statements (aka multiple way branch statements) and are called other things in other languages:FORTRAN IV - computed GOTO statementFortran 95 - case constructBASIC - ON ... GOTO statementCOBOL - EVALUATE statementPL/1 - SELECT statementPascal - case statementAda - case statementetc.
Perhaps you meant 'switch statement' instead of 'a switch'?Something like this: -> -> switch () -> { } -> (empty) | -> []; -> | -> case: | default: -> | break;
BNF, or Backus-Naur Form, is a notation used to express the grammar of programming languages. A switch-case structure can be represented in BNF as follows: <switch-statement> ::= "switch" "(" <expression> ")" "{" <case-clause>* <default-clause>? "}" <case-clause> ::= "case" <constant> ":" <statement>* <default-clause> ::= "default" ":" <statement>* This defines a switch statement consisting of an expression, multiple case clauses, and an optional default clause.
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.
The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.
yes,we can
If you must evaluate two or more expressions separately, use multiple if statements. If you only need to test all the possible evaluations of a single expression, use a switch.
I really think this is not possible.
In the general subject of computer programming neither switch nor transistor exist as concepts. They are out of scope.The language C (and its relatives) have a switch statement, but still no concept of transistor.The switch statement of C is a statement in the general class of multiple way decision statements (aka multiple way branch statements) and are called other things in other languages:FORTRAN IV - computed GOTO statementFortran 95 - case constructBASIC - ON ... GOTO statementCOBOL - EVALUATE statementPL/1 - SELECT statementPascal - case statementAda - case statementetc.
Perhaps you meant 'switch statement' instead of 'a switch'?Something like this: -> -> switch () -> { } -> (empty) | -> []; -> | -> case: | default: -> | break;
An else statement is comparing to items, while a switch statement is used to compare multiple items. So if you need multiple results from one statement use a switch but for booleans or very specific functions use a if else statement. Else If ex. if(a=6){System.out.println("It is six");} else(){System.out.println("It is not six");} Switch ex. switch(a){ case 1: System.out.println("it is one"); break; case 2: System.out.println("it is two"); break; default: System.out.println("it is not one or two"); break; } Basically a switch is a good way to check against a lot of possibilities.
BNF, or Backus-Naur Form, is a notation used to express the grammar of programming languages. A switch-case structure can be represented in BNF as follows: <switch-statement> ::= "switch" "(" <expression> ")" "{" <case-clause>* <default-clause>? "}" <case-clause> ::= "case" <constant> ":" <statement>* <default-clause> ::= "default" ":" <statement>* This defines a switch statement consisting of an expression, multiple case clauses, and an optional default clause.
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).
C++ Provides a multiple branch selection called as switch. This selection statement succesively test against a list of integer or character constants. When a match is found the statements associate with constants are executed. When no match is found default statement is used.