In the example, the user is prompted to enter values for three numbers a, b and c. It then checks for the test condition (a>b). If this condition is true then it checks for the test condition (a>c) using the if-else block contained in it. If the condition (a>c) evaluates to true then the message a is the Greatest is displayed otherwise the message c is the Greatest is displayed.
But if the condition (a>b) evaluates to false then it checks for the test condition (b >c) using another if-else statement contained within else block. If the condition (b>c) evaluates to true then the message b is the Greatest is displayed else the message c is the Greatest is displayed.
#include<iostream.h> #include<conio.h> #include<dos.h> void main() { int a,b,c,g; clrscr(); cout<<endl; cout<<"Enter the three numbers:"; cin>>a>>b>>c; if(a>b) { if(a>c) { g=a; } else { g=c; } } else { if(b>c) { g=b; } else { g=c; } } cout<<endl; cout<<"Greatest number is: "<<g; getch(); }