C++ Program/Code to input three nos. & print them in ascending order, using only the "if" Statement

Leave a Comment
// The Following program is all about finding the sequence of 3 inputted number in ascending order
//utilizing only 'if' statements...

#include<iostream>                         //For Input/Output Stream Related Functions
#include<conio.h>                           //For Console Input/Output function like clrscr & getche
using namespace std;                      //Using the "standard" namespace of iostream class

void main()
{
int a,b,c;
cout<<"Enter NUMBER:";
cin>>a>>b>>c;                                //User enters 3 numbers to compare
if(a>b&&a>c)                                  //First Condition
{
cout<<"\nThe highest no.:"<<a;
if(c>b)
{
cout<<"\nThe second highest no.:"<<c;
cout<<"\nThe smallest no:"<<b;
}
if(b>c)
{
cout<<"\nThe second highest no.:"<<b;
cout<<"\nThe smallest no:"<<c;
}
}
if(b>a&&b>c)                                  //Second Condition

cout<<"\nThe highest no.:"<<b;
if(a>c)
{
cout<<"\nThe second highest no.:"<<a;
cout<<"\nThe smallest no:"<<c;
}
if(c>a)
{
cout<<"\nThe second highest no.:"<<c;
cout<<"\nThe smallest no:"<<a;
}
}
if(c>a&&c>b)                                  //Third Condition

cout<<"\nThe highest no.:"<<c;
if(a>b)
{
cout<<"\nThe second highest no.:"<<a;
cout<<"\nThe smallest no:"<<b;
}
if(b>a)
{
cout<<"\nThe second highest no.:"<<b;
cout<<"\nThe smallest no:"<<a;
}
}
getche();                                          //To exit the program after an user's keystroke
}

0 comments: