I want a program using if condition to find big number

Status
Not open for further replies.
suppose you have three nos
a=9 b=10 c=11 then

Code:
if(a>b)
{
  if(a>c)
  {
    A is bigger
  }
  else
  {
    C is bigger
  }
}
else if(b>a)
{
 if(b>c)
 {
  b is bigger
 }
 else
 {
  C is bigger
 }
}
 

bignumber = 0;
if(a > bignumber) bignumber = a;
if(b >= bignumber) bignumber = b;
if(c >= bignumber) bignumber = c;

leaves the biggest of a,b and c in bignumber. It also caters for any of the numbers being equal and it uses one less compare instruction.
If you want to expand it to more numbers, put them in an array and loop through them using the same method.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…