if else statement
if else statement
When an if condition is true then the statements in if section are executed. When the condition is evaluated to false the statements in the else section will be executed
The syntax of if else statement is as follows
Some of the example programs on if else statement are shown in below:
Ex 1: A sample program on if else statement.
Output
enter your marks: 34
Pass |
Ex 2: A program on finding climate condition.
Output
Temperature : 43
Too hot |
Ex 3 Another example program on if else statement.
Output
Who is this : Sudhakar
Oh!Hi Sudhakar |
Ex 4 A program on if else statement using while loop
Output
1
2 3 4 5 Hello 7 8 9 10 |
Ex 5: A program on evaluation of marks
Output
enter marks 21 #Test case 1
total marks 36
enter marks 76 #Test case 2 total marks 86 |
Ex 6 A program to calculate the discount and print net payable
Output
Enter amount: 4589
Discount 458.90000000000003 Net payable: 4130.1 |
Ex 7: A program to find whether the given sides form a triangle or not.
Output
x= 45 #Test case 1
y= 31 z= 20 Yes it forms a triangle
x= 24 #Test case 2 y= 25 z= 56 impossible to form a triangle |