Asalam o
Alikum. I hope you all are fine by the grace of Allah Almighty.
Today I am
here with another program that will help you to make a simple arithmetic calculator using
switch statement.
Actually
switch statement is a good alternative of “if-else-if” or nested if-else.
It is very useful in a condition when there are many choices available and only
one should be executed.Its syntax is as follows:
Syntax
switch(expression)
{
case 1:
statements;
break;
case 2:
statements;
break;
.
.
default:
statements;
}
Below is the
source code of the above mentioned program:
Source code
Output
Explanation:
In this program,the result of a single expression is compared with multiple cases.If it matches with a certain case,the statement(s) below that case is executed.After execution,it comes out of the "switch" body due to "break" statement.This is actually the logic of this program.
No comments:
Post a Comment