Re: Newbie Problem



Larry Tooley wrote:
I am new to C and am using "C How to Program" to get started with my C
education. I am working an exercise where I am supposed to use only
arithmetic, equity and relational operators, and the "if" statement to
determine the largest and smallest of three integers. It seems like there
is an easy answer, but I just haven't come up with a solution. It has
been a long time since CS101 with Pascal so pardon my ignorance.

Thanks for the help.

Larry

/*Maximum of three integers*/
int max(int a,int b,int c)
{
return ((a>b&&a>c)? a:(a>b &&a<c)? c:(b>c)?b:c);
}
/*Minimum of three integers*/
int min(int a,int b,int c)
{
return ((a<b && a<c)?a:(a>b&&a<c)?b:(b<c)?b:c);
}
.



Relevant Pages

  • Re: Newbie Problem
    ... use only arithmetic, equity and relational operators, and the "if" ... int main { ... OP's requirement of using only "arithmetic, equity and relational ... Again, optimization wasn't the goal here, providing a solution that ...
    (comp.lang.c)
  • Re: Newbie Problem
    ... I am working an exercise where I am supposed to use only ... arithmetic, equity and relational operators, and the "if" statement to ... int main { ...
    (comp.lang.c)
  • Re: Newbie Problem
    ... I am working an exercise where I am supposed to use only ... arithmetic, equity and relational operators, and the "if" statement to ... int max ...
    (comp.lang.c)
  • Re: Newbie Problem
    ... arithmetic, equity and relational operators, and the "if" statement to ... value of the biggest integer. ... int max ...
    (comp.lang.c)
  • Re: Newbie Problem
    ... I am working an exercise where I am supposed to use only ... arithmetic, equity and relational operators, and the "if" statement to ... int max ...
    (comp.lang.c)