Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Largest Number using IF statements

Status
Not open for further replies.

MsPeppa

Programmer
Jun 27, 2001
19
US
If I was to read in 7 integers and I wanted to find the largest number using only if statements (no arrays) but also keep the amount of code to a reasonable amount, does anyone know how to do that?
 
Not saying this is the best way, just the method that comes to mind.
int Best = Value1;
if (Value2 > Best) Best = Value2;
if (Value3 > Best) Best = Value3;
if (Value4 > Best) Best = Value4;
if (Value5 > Best) Best = Value5;
if (Value6 > Best) Best = Value6;
if (Value7 > Best) Best = Value7;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top