# how to get the ascending and descending of 4 integers with out using array,&&,or only using function

#include <iostream>

using namespace std;

void sort4Nums(int,int,int,int,short);

int main()

{

char tr;

short option;

do

{

int num1,num2,num3,num4;

system("cls");

cout<<"Enter four integers : \n";

cin>>num1>>num2>>num3>>num4;

cout<<"How would you like to display the result ? \n";

cout<<"1. Ascending order \n2. Descending order \n";

cin>>option;

switch(option)

{

case 1:

cout<<"Ascending order : \n";

sort4Nums(num1,num2,num3,num4,1);

break;

case 2:

cout<<"Descending : \n";

sort4Nums(num1,num2,num3,num4,2);

break;

default:

cout<<"\n Invalid option. \n";

break;

}

cout<<"\nPress Y/y to try again.\n";

cin>>tr;

}while(tr=='y' or tr=='Y');

system("pause");

return 0;

}

void sort4Nums(int n1,int n2,int n3,int n4,short op)

{

if(n1>=n2)

{

if(n2>=n3)

{

if(n3>=n4)

{

if(op==1)

cout<<n4<<" => "<<n3<<" => "<<n2<<" => "<<n1;

else

cout<<n1<<" => "<<n2<<" => "<<n3<<" => "<<n4;

}

else if(n1>=n4)

{

if(op==1)

cout<<n2<<" => "<<n3<<" => "<<n4<<" => "<<n1;

else

cout<<n1<<" => "<<n4<<" => "<<n3<<" => "<<n2;

}

else

{

if(op==1)

cout<<n2<<" => "<<n1<<" => "<<n4<<" => "<<n3;

else

cout<<n3<<" => "<<n4<<" => "<<n1<<" => "<<n2;

}

}

else if(n1>=n4)

{

if(op==1)

cout<<n4<<" => "<<n3<<" => "<<n1<<" => "<<n2;

else

cout<<n2<<" => "<<n1<<" => "<<n3<<" => "<<n4;

}

else if(n2>=n4)

{

if(op==1)

cout<<n1<<" => "<<n3<<" => "<<n4<<" => "<<n2;

else

cout<<n2<<" => "<<n4<<" => "<<n3<<" => "<<n1;

}

else

{

if(op==1)

cout<<n1<<" => "<<n2<<" => "<<n3<<" => "<<n4;

else

cout<<n4<<" => "<<n3<<" => "<<n2<<" => "<<n1;

}

}

}