hi
How to find biggest of three numbers without comaprimg numbers
May 4 '06
30 13906
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************ **********@rand om.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 signedrightshif t(v,s) ((v) / (1 << (s)))
/* On real platforms */
#define signedrightshif t(v,s) ((v) >> (s))
static int maskgt (int a, int b) {
int v = ((a^b) & b)  ((~(a^b)) & (b  a));
return signedrightshif t (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************ **********@rand om.yi.org> Jordan Abel <ra*******@gmai l.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************ **********@rand om.yi.org> Jordan Abel <ra*******@gmai l.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(B IGGER_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 "technicall y correct" English; but since when was rock & roll "technicall y 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 "technicall y correct" English; but since when was rock & roll "technicall y correct"?
On 20060507, Peter "Shaggy" Haywood <ph******@alpha link.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics 
by: Neal 
last post by:
I'm thinking about so many posts I've read and answered in the past month
 here's where my brain is at. Feel free to add and comment as you see fit.
The biggest problem in web design is choosing that design before the
content is set.
Content is king. We need to set things up to display the text content. The
smart designer knows that the user might size the text any which way, so
the design needs to flex to the text size over any other...

by: esparkman 
last post by:
Hey guys! 1st time poster here. Got a quick question. I'm just
beginning my journey into csharp and am developing a win32 app that
will retrieve a given useres account pull raw data from a db and
display that info. One of the things i need t odo is look at 7 entries
and compare those and then decide which is biggest and display that.
I am stuck. Can anyone help me out. I'm in no way asking for someone to
do this and me strip the code i...

by: fdmfdmfdm 
last post by:
let's say without checking including files, how do we to represent the
biggest say int in a system?
I ran across a book give this code:
long int biggest = 0x7FFFFFFF;
Does that mean the long int at that system is only 32 bits? If we know
in a particular system, the long int is 64 bits, shall we write:

by: marktang 
last post by:
ONU (Optical Network Unit) is one of the key components for providing highspeed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...

by: Hystou 
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
 
by: Oralloy 
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bitfields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++12 std=c++20 Wnarrowing bit_field.cpp
Here is the code in...

by: tracyyun 
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, ZWave, WiFi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

by: isladogs 
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...

by: conductexam 
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...

by: TSSRALBI 
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LANtoLAN VPNs.
The last exercise I practiced was to create a LANtoLAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

by: 6302768590 
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
 
by: bsmnconsultancy 
last post by:
In today's digital era, a welldesigned website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
 