Page 44 - Modular_V1.1_Flipbook
P. 44
int first_no, second_no, third_no;
clrscr();
cout<<”Enter first number: “;
cin>>first_no;
cout<<”Enter second number: “;
cin>>second_no;
cout<<”Enter third number: “;
cin>>third_no;
if((first_no > second_no) && (first_no > third_no))
{
cout<<”The largest number is: “<<first_no;
}
Output1:
else
Enter first number: 23
if((second_no > third_no) && (second_no > first_no))
{ Enter second number: 26
cout<<”The largest number is: “<<second_no; Enter third number: 54
} The largest number is: 54
else{ Output2:
cout<<”The largest number is: “<<third_no;
Enter first number: 263
}
Enter second number: 236
getch();
Enter third number: 547
}
The largest number is: 547
THE IF…ELSE…IF LADDER
The if…else…if ladder is another type of if statement. It helps us to test multiple conditions
and follows a top-down approach. As soon as the condition of the if evaluates to true, the
statements in that ‘if’ is executed, and rest of
the ladder is avoided. If none of the conditions
True
evaluates to true, then the final else statement Expression 1 Statement 1
gets executed. The syntax of if...else…if ladder
is shown below: False
if expression1
True
Expression 2 Statement 2
statement1;
else if expression2
False
statement2;
True
else if expression3 Statement 3
Expression 3
statement3;
. . . . . . . . . . . . . . . .
False Body of else
else
Statement just
statementN;
below if...else...if ladder
42 Touchpad MODULAR (Version 1.1)-X

