If a user enters 3 integers how do I find out which number is the largest? I'm pretty new to c++, right now I know how to use IF statements. Is there a way to find the largeste using IF? Thanks
Using "if"'s would not be the way to go for a large quantity of numbers but in your case with just 3 numbers it is a simple comparison
if(a<b)
{
if(b<c)
return c;
// know that b is largest
return b;
}
else
{
if(a<c)
return c;
return a;
}
That is the basics of it, though I would suggest looking into a loop because as the number of numbers you have increases, this code will grow exponentially.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.