Monday, 30 March 2015

C++ code for Finding out The Greatest Number


To Find The Greatest Number:

#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,num3,num4,num5;
cout<<" Enter value for first number";
cin>>num1;
cout<<" Enter value for second number";
cin>>num2;
cout<<" Enter value for third number";
cin>>num3;
cout<<" Enter value for fourth number";
cin>>num4;
cout<<" Enter value for fifth number";
cin>>num5;
if(num1>num2&&num1>num3&&num1>num4&&num1>num5)
{
cout<<" First number is greatest"<<endl<<"which is= "<<num1;
}
if (num1<num2&&num1<num3&&num1<num4&&num1<num5)
{
cout<<" First number is smallest"<<endl<<"which is= "<<num1;
}
else if(num2>num1&&num2>num3&&num2>num4&&num2>num5)
{
cout<<" Second number is greatest"<<endl<<"which is= "<<num2;
}
if(num2<num1&&num2<num3&&num2<num4&&num2<num5)
{
cout<<" Second number is smallest"<<endl<<"which is= "<<num2;
}
else if (num3>num1&&num3>num2&&num3>num4&&num3>num5)
{
cout<<" Third number is greatest"<<endl<<"which is= "<<num3;
}
if (num3<num1&&num3<num2&&num3<num4&&num3<num5)
{
cout<<" Third number is smallest"<<endl<<"which is= "<<num3;
}
else if (num4>num1&&num4>num2&&num4>num3&&num4>num5)
{
cout<<" Fourth number is greatest"<<endl<<"which is= "<<num4;
}
if (num4<num1&&num4<num2&&num4<num3&&num4<num5)
{
cout<<" Fourth number is smallest"<<endl<<"which is= "<<num4;
}
else if (num5>num1&&num5>num2&&num5>num3&&num5>num4)
{
cout<<" Fifth number is grestest"<<endl<<"which is= "<<num5;
}
else if (num5<num1&&num5<num2&&num5<num3&&num5<num4)
{
cout<<" Fifth number is smallest"<<endl<<"which is= "<<num5;
}

getch();
}






No comments: