by Dinesh Thakur Category: Control Structures

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();
}

Greatest Number Among Three Integer Numbers



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles