
hi
How to find biggest of three numbers without comaprimg numbers  
Share:

vim wrote: hi How to find biggest of three numbers without comaprimg numbers
return a>b?a>c?a:c:b>c?b:c;
No comaprisoms were haremd in the comuptatiom of this reslut.

Eric Sosman es*****@acmdotorg.invalid   
vim wrote: hi How to find biggest of three numbers without comaprimg numbers
Have someone else compare them for you and tell you what the biggest
one is. Do you have a C language question?
Robert Gamble   
Op Thu, 04 May 2006 13:48:13 +0200 schreef vim <vg*****@gmail.com>: hi How to find biggest of three numbers without comaprimg numbers
Without a comparison, the notion of 'biggest' is meaningless.

Gemaakt met Opera's revolutionaire emailprogramma: http://www.opera.com/mail/   
On 20060504, vim <vg*****@gmail.com> wrote: hi How to find biggest of three numbers without comaprimg numbers
First, write an algorithm to find the biggest of two numbers without
comparing them.
Then
maxof3(a, b, c) {
return max(a,max(b,c));
}
This can be extended recursively to find the biggest of four, five, etc
numbers.   
vim wrote: hi How to find biggest of three numbers without comaprimg numbers
Ask someone else to compare them for you.
The comparison operators are there for a reason, do you have a good
reason for not using them? If your reason is your instructor told you
not to then that is a very good reason for us to *not* give you the
solution.

Flash Gordon, living in interesting times.
Web site  http://home.flashgordon.me.uk/
comp.lang.c posting guidelines and intro: http://clcwiki.net/wiki/Intro_to_clc   
In article <sl**********************@random.yi.org> Jordan Abel <ra*******@gmail.com> writes: On 20060504, vim <vg*****@gmail.com> wrote: hi How to find biggest of three numbers without comaprimg numbers First, write an algorithm to find the biggest of two numbers without comparing them.
Yes.
Then
maxof3(a, b, c) { return max(a,max(b,c)); }
Oh, well, simply:
max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;

dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/   
[vim] How to find biggest of three numbers without comaprimg numbers
I've tried to use the division technique without actually using any
comparision operators
Looks nonsense but doesn't compare numbers :)
code snippet
{
int ia;
int ib;
int ic;
if(ia/ib && ic/ib) /*Division of a smaller int by a greater int
results in 0*/
{
printf("\n%d is the smallest\n",ib);
}
else if(ib/ia && ic/ia)
{
printf("\n%d is the smallest\n",ia);
}
else
{
printf("\n%d is the smallest\n",ic);
}
}

Sundar   
On 20060504, Dik T. Winter <Di********@cwi.nl> wrote: In article <sl**********************@random.yi.org> Jordan Abel <ra*******@gmail.com> writes: > On 20060504, vim <vg*****@gmail.com> wrote: > > hi > > How to find biggest of three numbers without comaprimg numbers > > First, write an algorithm to find the biggest of two numbers without > comparing them.
Yes.
> Then > > maxof3(a, b, c) { > return max(a,max(b,c)); > }
Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
More risk of overflow, though.   
Dik T. Winter wrote: In article <sl**********************@random.yi.org> Jordan Abel <ra*******@gmail.com> writes: > On 20060504, vim <vg*****@gmail.com> wrote: > > hi > > How to find biggest of three numbers without comaprimg numbers > > First, write an algorithm to find the biggest of two numbers without > comparing them.
Yes.
> Then > > maxof3(a, b, c) { > return max(a,max(b,c)); > }
Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
nice peace of code, got me a while that it comes from:
max(a,b) = (a + b + abs(a  b))/2
but using this the comparison is simple hidden in the
abs statement, where a number is compared to zero. :)   
Eric Sosman wrote: vim wrote:
hi How to find biggest of three numbers without comaprimg numbers
return a>b?a>c?a:c:b>c?b:c;
No comaprisoms were haremd in the comuptatiom of this reslut.
Thanks. Now I have coffee sprayed all over my monitor and keyboard.   
Op 4 May 2006 06:07:26 0700 schreef Sundar: [vim]How to find biggest of three numbers without comaprimg numbers
I've tried to use the division technique without actually using any comparision operators Looks nonsense but doesn't compare numbers :) code snippet { int ia; int ib; int ic;
if(ia/ib && ic/ib) /*Division of a smaller int by a greater int results in 0*/ { printf("\n%d is the smallest\n",ib); } else if(ib/ia && ic/ia) { printf("\n%d is the smallest\n",ia); } else { printf("\n%d is the smallest\n",ic); } }  Sundar
The Romans would not have problems with this, but since an Indian lady
discovered it about a millenium ago, we have the number zero!
There is a fair chance that ia, ib or ic has this value.

Coos   
vim wrote: hi How to find biggest of three numbers without comaprimg numbers
Anything you might do to find the biggest of three numbers counts as
comparison.   
Jordan Abel wrote: On 20060504, Dik T. Winter <Di********@cwi.nl> wrote: In article <sl**********************@random.yi.org> Jordan Abel writes: > On 20060504, vim <vg*****@gmail.com> wrote: > > How to find biggest of three numbers without comaprimg numbers > > First, write an algorithm to find the biggest of two numbers without > comparing them.
Yes.
> Then > > maxof3(a, b, c) { > return max(a,max(b,c)); > }
Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
More risk of overflow, though.
Indeed, so try this:
/* On an old CRAY: */
#define signedrightshift(v,s) ((v) / (1 << (s)))
/* On real platforms */
#define signedrightshift(v,s) ((v) >> (s))
static int maskgt (int a, int b) {
int v = ((a^b) & b)  ((~(a^b)) & (b  a));
return signedrightshift (v, sizeof (int) * CHAR_BIT  1);
}
int max (int a, int b) {
int v = maskgt (a, b);
return (v & a)  (~v & b);
}
Disclaimer: I have no idea what this will do on 1s complement machines,
and more than likely neither do you.

Paul Hsieh http://www.pobox.com/~qed/ http://bstring.sf.net/   
Bart Rider wrote: Dik T. Winter wrote: In article <sl**********************@random.yi.org> Jordan Abel <ra*******@gmail.com> writes: > On 20060504, vim <vg*****@gmail.com> wrote: > > hi > > How to find biggest of three numbers without comaprimg numbers > > First, write an algorithm to find the biggest of two numbers without > comparing them.
Yes.
> Then > > maxof3(a, b, c) { > return max(a,max(b,c)); > }
Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
nice peace of code, got me a while that it comes from: max(a,b) = (a + b + abs(a  b))/2
but using this the comparison is simple hidden in the abs statement, where a number is compared to zero. :)
The ABS function can be done without comparisons: first by
forcing the sign positive; second (and agreed, it is slow!)
by
ABS(a) = SQRT(a*a)

Julian V. Noble
Professor Emeritus of Physics
University of Virginia   
Julian V. Noble wrote: Bart Rider wrote: Dik T. Winter wrote: In article <sl**********************@random.yi.org> Jordan Abel <ra*******@gmail.com> writes: > On 20060504, vim <vg*****@gmail.com> wrote: > > hi > > How to find biggest of three numbers without comaprimg numbers > > First, write an algorithm to find the biggest of two numbers without > comparing them.
Yes.
> Then > > maxof3(a, b, c) { > return max(a,max(b,c)); > }
Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
nice peace of code, got me a while that it comes from: max(a,b) = (a + b + abs(a  b))/2
but using this the comparison is simple hidden in the abs statement, where a number is compared to zero. :)
The ABS function can be done without comparisons: first by forcing the sign positive; second (and agreed, it is slow!) by ABS(a) = SQRT(a*a)
And how, you might ask, do you force the sign positive? For IEEE
fp numbers it is easy: the leftmost (most significant) bit is
the sign, so for 32bit fp numbers you AND with hex 7FFF and with
64bit numbers, AND with 7FFFFFFF . I suppose there is something
similar one can do with 2's complement integers.

Julian V. Noble
Professor Emeritus of Physics
University of Virginia   
Jordan Abel wrote: On 20060504, vim <vg*****@gmail.com> wrote: hi How to find biggest of three numbers without comaprimg numbers
First, write an algorithm to find the biggest of two numbers without comparing them.
Here's one I prepared earlier... http://groups.google.com/group/comp....eee18e55ea156c

Peter   
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in
comp.lang.c.
biggest of 3 numbers's a cool scene! Dig it! How to find biggest of three numbers without comaprimg numbers
And your C question is...?
Find the bigger of three numbers by finding the bigger of two
numbers, one of which is itself the bigger of two numbers. Find the
bigger of two numbers by subtracting one from the other and
determining whether the result is greater than zero or not.
#define BIGGER_OF_TWO(x,y) ((x)  (y) > 0 ? (x) : (y))
#define BIGGER_OF_THREE(x,y,z) BIGGER_OF_TWO(BIGGER_OF_TWO(x, y), z)

Dig the even newer still, yet more improved, sig! http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?"  Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?   
Groovy hepcat Sundar was jivin' on 4 May 2006 06:07:26 0700 in
comp.lang.c.
Re: biggest of 3 numbers's a cool scene! Dig it! How to find biggest of three numbers without comaprimg numbers I've tried to use the division technique without actually using any comparision operators Looks nonsense but doesn't compare numbers :) code snippet { int ia; int ib; int ic;
if(ia/ib && ic/ib) /*Division of a smaller int by a greater int results in 0*/
So does division of an int by a smaller int large enough to cause a
value of magnitude less than 1, such as 8/7 or 32/17.
{ printf("\n%d is the smallest\n",ib); } else if(ib/ia && ic/ia) { printf("\n%d is the smallest\n",ia); } else { printf("\n%d is the smallest\n",ic); } }
Doomed to failure, I'd say.

Dig the even newer still, yet more improved, sig! http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?"  Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?   
On 20060507, Peter "Shaggy" Haywood <ph******@alphalink.com.au.NO.SPAM> wrote: Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in comp.lang.c. biggest of 3 numbers's a cool scene! Dig it!
How to find biggest of three numbers without comaprimg numbers
And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
What's 32760  (32760)?
65520, right?
Or maybe it's 10.   
Peter Shaggy Haywood schrieb: Groovy hepcat Sundar was jivin' on 4 May 2006 06:07:26 0700 in comp.lang.c. Re: biggest of 3 numbers's a cool scene! Dig it!
How to find biggest of three numbers without comaprimg numbers
I've tried to use the division technique without actually using any comparision operators Looks nonsense but doesn't compare numbers :) code snippet { int ia; int ib; int ic;
if(ia/ib && ic/ib) /*Division of a smaller int by a greater int results in 0*/
So does division of an int by a smaller int large enough to cause a value of magnitude less than 1, such as 8/7 or 32/17.
Could you please explain that?
I would have expected a "rounddown behaviour for negative
results" argument but I fail to see how 8/7 <= 1 in C.
Maybe it's just my not having had my caffeine fix yet...
Cheers
Michael

EMail: Mine is an /at/ gmx /dot/ de address.   
Jordan Abel schrieb: On 20060507, Peter "Shaggy" Haywood <ph******@alphalink.com.au.NO.SPAM> wrote:
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in comp.lang.c. biggest of 3 numbers's a cool scene! Dig it!
How to find biggest of three numbers without comaprimg numbers
And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
What's 32760  (32760)?
65520, right?
Or maybe it's 10.
ITYM 0x10 or 16
Cheers
Michael

EMail: Mine is an /at/ gmx /dot/ de address.   
On 20060507, Michael Mair <Mi**********@invalid.invalid> wrote: Jordan Abel schrieb: On 20060507, Peter "Shaggy" Haywood <ph******@alphalink.com.au.NO.SPAM> wrote:
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in comp.lang.c. biggest of 3 numbers's a cool scene! Dig it!
How to find biggest of three numbers without comaprimg numbers
And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
What's 32760  (32760)?
65520, right?
Or maybe it's 10.
ITYM 0x10 or 16
Or it could be 10. or 42. But that is what I meant.   
In article <4b*************@news.dfncis.de> Bart Rider <ca*******@killamail.com> writes: Dik T. Winter wrote:
.... Oh, well, simply: max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4;
nice peace of code, got me a while that it comes from: max(a,b) = (a + b + abs(a  b))/2
but using this the comparison is simple hidden in the abs statement, where a number is compared to zero. :)
Well, assuming those are ints:
unsigned int abs(int n)
{
unsigned int x = n;
unsigned int m;
m = (1 << (sizeof(int)  1)) & x;
m = (m  (m >> 31))  m;
return (x ^ m) + (1 & m);
}
Where is the comparison? But, whatever, abs is standard already in C89,
and I have no idea how it is implemented... But of course, there is
the probability of overflow lurking in that formula.

dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/    ph******@alphalink.com.au.NO.SPAM (Peter "Shaggy" Haywood) wrote: Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in
How to find biggest of three numbers without comaprimg numbers
And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
#define BIGGER_OF_TWO(x,y) ((x)  (y) > 0 ? (x) : (y))
0 is not a number these days?
Richard   
Richard Bos wrote: ph******@alphalink.com.au.NO.SPAM (Peter "Shaggy" Haywood) wrote:
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in
How to find biggest of three numbers without comaprimg numbers And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
#define BIGGER_OF_TWO(x,y) ((x)  (y) > 0 ? (x) : (y))
0 is not a number these days?
It doesn't matter which you return if the difference is 0, and the
suggested expression will return one of the numbers in that case. So I
don't see your point.

Flash Gordon, living in interesting times.
Web site  http://home.flashgordon.me.uk/
comp.lang.c posting guidelines and intro: http://clcwiki.net/wiki/Intro_to_clc   
In article <Iy********@cwi.nl> "Dik T. Winter" <Di********@cwi.nl> writes: In article <4b*************@news.dfncis.de> Bart Rider <ca*******@killamail.com> writes: > Dik T. Winter wrote: ... > > Oh, well, simply: > > max = (a + b + c * 2 + abs(a  b) + abs(a + b  c * 2 + abs(a  b))) / 4; > > nice peace of code, got me a while that it comes from: > max(a,b) = (a + b + abs(a  b))/2 > > but using this the comparison is simple hidden in the > abs statement, where a number is compared to zero. :)
Well, assuming those are ints:
unsigned int abs(int n) { unsigned int x = n; unsigned int m;
m = (1 << (sizeof(int)  1)) & x; m = (m  (m >> 31))  m;
Should have been
m = (m  (m >> (sizeof(int)  1)))  m;
return (x ^ m) + (1 & m); }
Where is the comparison? But, whatever, abs is standard already in C89, and I have no idea how it is implemented... But of course, there is the probability of overflow lurking in that formula.

dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/   
Flash Gordon <sp**@flashgordon.me.uk> wrote: Richard Bos wrote: ph******@alphalink.com.au.NO.SPAM (Peter "Shaggy" Haywood) wrote:
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in
How to find biggest of three numbers without comaprimg numbers And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
#define BIGGER_OF_TWO(x,y) ((x)  (y) > 0 ? (x) : (y))
0 is not a number these days?
It doesn't matter which you return if the difference is 0, and the suggested expression will return one of the numbers in that case. So I don't see your point.
The requirement was "without comparing numbers". (Ok, as written it was
"without comaprimg numbers", but...) Zero is a number. Comparing
something to zero falls under comparing numbers, and is therefore non
grata in this homework assignment.
Richard   
Richard Bos wrote: Flash Gordon <sp**@flashgordon.me.uk> wrote:
Richard Bos wrote: ph******@alphalink.com.au.NO.SPAM (Peter "Shaggy" Haywood) wrote:
Groovy hepcat vim was jivin' on 4 May 2006 04:48:13 0700 in
> How to find biggest of three numbers without comaprimg numbers And your C question is...? Find the bigger of three numbers by finding the bigger of two numbers, one of which is itself the bigger of two numbers. Find the bigger of two numbers by subtracting one from the other and determining whether the result is greater than zero or not.
#define BIGGER_OF_TWO(x,y) ((x)  (y) > 0 ? (x) : (y)) 0 is not a number these days? It doesn't matter which you return if the difference is 0, and the suggested expression will return one of the numbers in that case. So I don't see your point.
The requirement was "without comparing numbers". (Ok, as written it was "without comaprimg numbers", but...) Zero is a number. Comparing something to zero falls under comparing numbers, and is therefore non grata in this homework assignment.
OK, I missed the point you were making. I agree with you.

Flash Gordon, living in interesting times.
Web site  http://home.flashgordon.me.uk/
comp.lang.c posting guidelines and intro: http://clcwiki.net/wiki/Intro_to_clc
Inviato da XPrivat.Org  Registrazione gratuita http://www.xprivat.org/join.php   
Groovy hepcat Michael Mair was jivin' on Sun, 07 May 2006 08:28:48
+0200 in comp.lang.c.
Re: biggest of 3 numbers's a cool scene! Dig it! Peter Shaggy Haywood schrieb: Groovy hepcat Sundar was jivin' on 4 May 2006 06:07:26 0700 in comp.lang.c. Re: biggest of 3 numbers's a cool scene! Dig it!
How to find biggest of three numbers without comaprimg numbers
I've tried to use the division technique without actually using any comparision operators Looks nonsense but doesn't compare numbers :) code snippet { int ia; int ib; int ic;
if(ia/ib && ic/ib) /*Division of a smaller int by a greater int results in 0*/
So does division of an int by a smaller int large enough to cause a value of magnitude less than 1, such as 8/7 or 32/17.
Could you please explain that? I would have expected a "rounddown behaviour for negative results" argument but I fail to see how 8/7 <= 1 in C. Maybe it's just my not having had my caffeine fix yet...
I don't know what I'm talking about. I really gotta get some sleep.
Well, that's my excuse anyhow, and I'm sticking to it. :)

Dig the even newer still, yet more improved, sig! http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?"  Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?   
If u compare the result( subtraction of two numbers ) with 0.Then it it
violates the condition.
There should be no comparision   This discussion thread is closed Replies have been disabled for this discussion. Similar topics
4 posts
views
Thread by Neal 
last post: by

3 posts
views
Thread by esparkman 
last post: by

29 posts
views
Thread by fdmfdmfdm 
last post: by
          