Hi to all. find out the biggest among two numbers without using any
conditional statements and any relational operators. 50 4175
sabarish wrote: Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
This cannot be done, not even by using non-portable
trickery. The reason is simple: there is no such thing
as the "biggest" of just two numbers. The superlative
form of an adjective implies three or more alternatives.
Had you written "bigger" the answer might have been
different -- but that would have made the question sound
like homework, and we can't have that, can we?
-- Er*********@sun .com
Eric Sosman <er*********@su n.com> wrote: sabarish wrote: Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
This cannot be done, not even by using non-portable trickery. The reason is simple: there is no such thing as the "biggest" of just two numbers. The superlative form of an adjective implies three or more alternatives.
No, they don't. Check the OED. What you describe is merely customary in
some circles, but not the only correct usage.
Richard
sabarish wrote: Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
So, how many open NNTP proxies do you have access to?
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
result=(x-y) //subtract y from x
//if x>y result is +ve else -ve
result=result >>31 //get the sign bit to last bit
result=result&0 x01 //mask the last bit
return x*result + y*(~result & 0x1)
if result =1 x will be returned as ~result&0x1 would be 0
In article <11************ **********@g47g 2000cwa.googleg roups.com>,
<ag************ *@gmail.com> wrote: result=(x-y) //subtract y from x //if x>y result is +ve else -ve
Why would the result be negative if the two values are equal?
--
This signature intentionally left... Oh, darn!
Richard Bos wrote: Eric Sosman <er*********@su n.com> wrote:
sabarish wrote:
Hi to all. find out the biggest among two numbers without using any conditiona l statements and any relational operators. This cannot be done, not even by using non-portable trickery. The reason is simple: there is no such thing as the "biggest" of just two numbers. The superlative form of an adjective implies three or more alternatives.
No, they don't. Check the OED.
No thanks; I've got other uses for $295.
What you describe is merely customary in some circles, but not the only correct usage.
"Some circles" meaning "Those who value English," I
guess ...
Does the OED list "irregardle ss?" Does it list "verb"
as a transitive verb? Does it endorse the sportscasters'
monstrous misuse of the present indicative for the subjunctive
("If I'm Alex Rodriguez I'm looking fast ball here")? We're
down to the old prescriptive vs. descriptive debate, and I for
one choose not use a description of other people's bad usage
as a prescription for my own. Harrumph!
-- Er*********@sun .com
"sabarish" <su******@gmail .com> writes: Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
This question has been beaten to death over the years. Try
searching the archives.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield
sabarish wrote: Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
It's simple as well as off topic (since it's not C specific):
max(x, y) = (x + y + |x - y|) / 2
August ag************* @gmail.com writes: result=(x-y) //subtract y from x //if x>y result is +ve else -ve
result=result >>31 //get the sign bit to last bit result=result&0 x01 //mask the last bit
return x*result + y*(~result & 0x1)
if result =1 x will be returned as ~result&0x1 would be 0
That has so many portability problems I'm not going to bother to
decide whether it's correct.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Mantoulidis |
last post by:
I posted this here one day ago but it seems like it hasn't been put up
for some unknown reason. That gives me a chance to say things a bit
better in this post.
1st of all let's desribe the problem: In ParamGenerate() I want to
find all whitespaces before a certain point in one string. Thus I use
the string::find() function. However it seems like this function
ignores some whitespaces :/ This is really weird and I need your help.
Okay...
|
by: Bryan Olson |
last post by:
The Python slice type has one method 'indices', and reportedly:
This method takes a single integer argument /length/ and
computes information about the extended slice that the slice
object would describe if applied to a sequence of length
items. It returns a tuple of three integers; respectively
these are the /start/ and /stop/ indices and the /step/ or
stride length of the slice. Missing or out-of-bounds indices
are handled in a manner...
|
by: Mike Labosh |
last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me
find out *why* a form is unloading, and then conditionally cancel the event.
In VB.NET, the Closing event passes a CancelEventArgs that lets me cancel
the Close() operation, but is there still any way to find out *why* a form
is closing?
This app as a form that needs to be loaded at startup, closed only at
shutdown, and then Show() / Hide() for the user. If...
|
by: DJTN |
last post by:
I'm getting the following error when I try to compile my setup project in VS
2002. I have re-installed the .net framework 1.1 and it didnt solve the
problem.
WARNING: Unable to find dependency 'mscorlib' (Signature='B77A5C561934E089'
Version='1.0.5000.0') of assembly 'System.dll'
WARNING: Unable to find dependency 'mscorlib' (Signature='B77A5C561934E089'
Version='1.0.5000.0') of assembly 'System.Windows.Forms.dll'
WARNING: Unable to...
|
by: Tony Girgenti |
last post by:
Hello.
I'm developing and testing a web application using VS.NET 2003, VB, .NET
Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2
computer. I'm using a web form.
For a datagrid control, i used the Caption property. It displays fine on
the datagrid and allows me to run the program.
But, when i view the HTML for the web form, it shows this error at the
| |
by: TheScullster |
last post by:
Hi all
Bit of an obscure one this, but hopefully someone will be able to help.
4 years ago we had a potentially catastrophic problem with our Access
database.
From memory it was written in Access 2000, but is now used on Access 2003.
The problem surrounded the Find button created using the wizard. There was
some issue with this procedure and linked tables.
|
by: Ko van der Sloot |
last post by:
Hello
I was wondering which behaviour might be expected (or is required) for
the following small program.
I would expect that find( "a", string::npos ) would return string::npos
but is seems to be dependant on which string is searched for.
On my system, using gcc 4.1.2, I get:
pos1=2
problem because pos1=0
|
by: moondaddy |
last post by:
I had to repost this because I had to update and change my msdn alias. I
will re-ask the question and clarify a few things that were not clear
before.
This code is all executed on my dev machine running winXP sp2 and VS2005.
I'm using a c# 2.0 winforms app which talks to a c#2.0 asp.net app that also
contains 1 web service. Note: the webpage and web service are located side
by side in the same web app.
|
by: JoeP |
last post by:
Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False
oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient
oSMTP.Send(oMailMessage) (in this line I am getting the above err)
|
by: zephyrus360 |
last post by:
This is about a technique to find the mod of a very large integer with a normal small integer.
I recently encountered this problem when I needed to compute the modulus of a very large number with a normal integer. I needed this in a C++ program running on a 32-bit UNIX platform. The problem was that the number was 28 digits long and no native datatype in c++ could store a number of that size.
(Eg: 1088263455689473669888943602 % 380)
Not...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed 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 bit-fields 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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, Z-Wave, Wi-Fi, 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |