Page 43 - Modular_V1.1_Flipbook
P. 43
void main()
{
int a, b, c;
clrscr();
cout <<”Enter the value of a: “;
cin >> a;
cout <<”Enter the value of b: “;
cin >> b;
a = a + 1;
b = b - 1;
c = b > a ? b : a; Output:
Enter the value of a: 21
cout <<”\n Value of a: “<<a++;
Enter the value of b: 43
cout <<”\n Value of b: “<<--b;
Value of a: 22
cout <<”\n Value of c: “<<c;
Value of b: 41
getch();
Value of c: 42
}
Nested if Statement
C++ allows you to use the if statement inside another if statement. It is called nested if statement.
The inner if statement will run only when the first if statement evaluates to true. The syntax of
nested if statement is shown below:
if(condition1) {
// statements
if(condition2) {
// statements
}
else
{
// statements
}
}
Program 4: To find the largest among three numbers.
#include <iostream.h>
#include<conio.h>
void main(){
Conditional Statements 41

