A
Amar Kumar Dubedy
How to find the greatest of three numbers without using any comparison
operator or ternary operator??
operator or ternary operator??
How to find the greatest of three numbers without using any comparison
operator or ternary operator??
If the numbers are positive integersAmar Kumar Dubedy said:How to find the greatest of three numbers without using any comparison
operator or ternary operator??
How to find the greatest of three numbers without using any comparison
operator or ternary operator??
Amar Kumar Dubedy said:How to find the greatest of three numbers without using any comparison
operator or ternary operator??
Army1987 wrote:
In what way is `==` not a comparison operator?
Army1987 said:#include <stdlib.h>
...
if (a - b == abs(a - b))...
#include <stdlib.h>
...
if (a - b == abs(a - b))...
(but beware of overflows...)
Amar Kumar Dubedy said:How to find the greatest of three numbers without using any comparison
operator or ternary operator??
Richard Tobin said:Perhaps Army was thinking of "relational operator", which C defines
as not including the equality operators.
Amar Kumar Dubedy said:How to find the greatest of three numbers without using any comparison
operator or ternary operator??
int norz(int a, int b)
{ return(a*ceil((a/b)*((float)b/a))); }
Richard said:cr88192 said: [un-snip]just a guess really (assumes 3 integers > 0).int norz(int a, int b)
{ return(a*ceil((a/b)*((float)b/a))); }
Fails when b is 0.
Richard said:cr88192 said: [un-snip]just a guess really (assumes 3 integers > 0).int norz(int a, int b)
{ return(a*ceil((a/b)*((float)b/a))); }
Fails when b is 0.
If b is 0, then you don't have three integers > 0.
If we allow that the number must be positive integers then it turns into aRichard Heathfield said:Harald van D?k said:
Richard said:cr88192 said: [un-snip]
just a guess really (assumes 3 integers > 0).
int norz(int a, int b)
{ return(a*ceil((a/b)*((float)b/a))); }
Fails when b is 0.
If b is 0, then you don't have three integers > 0.
In which case we have demonstrated that the assumption is false.
Note that this assumption was not present in the OP.
If we allow that the number must be positive integers then it turns intoRichard Heathfield said:Harald van D?k said:
Richard Heathfield wrote:
cr88192 said:
[un-snip]
just a guess really (assumes 3 integers > 0).
int norz(int a, int b)
{ return(a*ceil((a/b)*((float)b/a))); }
Fails when b is 0.
If b is 0, then you don't have three integers > 0.
In which case we have demonstrated that the assumption is false.
Note that this assumption was not present in the OP.
a trival problem of C syntax, which I don't mind helping the OP with
even if it is homework.
Make them arbitrary floating point numbers and it is a lot more
difficult. Specify that the operation must not overflow machine
precision for any legal input and I think it might be impossible.
Amar said:How to find the greatest of three numbers without using any comparison
operator or ternary operator??
Richard Heathfield said:cr88192 said:
Fails when b is 0.
cr88192 said:oh well, the main reason I was here was seing if this was a good place to
talk about compiler writing and design (namely, I wrote a C compiler),
..., but it does not look like it, which is why I have not posted on this
subject here...
Amar Kumar Dubedy said:How to find the greatest of three numbers without using
any comparison operator or ternary operator??
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.