Nested Conditional Statment
Nested Conditional Statment
multiple if:
syntax:
if(expression)
{
Body of if(statement);
}
if(expression)
{
Body of if(statement);
}
In this selection statement a set of instruction are dependent on the condition/expression of selection
statement if condition/expression is true body of selection statement will be executed. But it is quite
different from above mention statements. Because, if any selection statement is true it will not have
skipped any statement. Each and every selection statement will be tested and executed accordingly.
nested if:
syntax:
if(expression)
{
if(expression)
{
Body of if(statement);
}
}
In this selection statement a set of instruction are dependent on the condition/expression of selection
statement if condition/expression is true body of selection statement will be executed which is another
selection statement.
Task 1
Write a program that takes one value from the user, asks about the type of conversion and then
performs a conversion depending on the type of conversion.
If user enters:
Task 2
Write and run a program that plays the game of “Rock, paper, scissors.” In this game, two players
simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The
winner is the one whose choice dominates the other. The rules are: paper dominates rock, rock
dominates scissors, and scissors dominate paper. You can use 1=rock,2=paper,3=scissors
Sample Input: 1 1
Write and run a program that reads two integers and then uses the conditional expression operator
to print either “multiple” or “not” according to whether one of the integers is a multiple of the
other.
Sample Input: 12 6
Output: 12 = 6 * 2
Sample Input: 18 8
Output: 18 = 8 * 2 + 2
Sample Input: 12 13
Output: 14 = 12 * 1 + 1
Task 4
Write and run a program that simulates a simple calculator. It reads two integers and a character. If
the character is a ‘+’, the sum is printed; if it is a ‘-‘, the difference is printed; if it is a ‘*’, the product
is printed; if it is a ‘/’, the quotient is printed; and if it is a ‘%’, the remainder is printed.