如何找到最少两个数字。 [英] How to find minimum of two numbers.

查看:78
本文介绍了如何找到最少两个数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这可能是一个愚蠢的问题。我正在寻找一个技巧

使用条件语句/运算符(''if'',''''在没有

的情况下,可以找到最少两个正整数'等等。)

解决方案

pradt,


以下怎么样?


min(a,b)=(1/2)* abs(a + b) - (1/2)* abs(ab)


请注意,从CS的角度来看,这实际上只是掩盖了运算符abs的定义中的条件

(无论如何都是在大多数

语言中预定义的)。


干杯,

Travis

pr * **@yahoo.com 写道:

这可能是一个愚蠢的问题。我正在寻找一个技巧,用
使用条件语句/运算符(''if'',''?''等)使用条件语句/运算符(<'blockquote)来创建最少两个正整数。


上传 pr***@yahoo.com

这可能是一个愚蠢的问题。我正在寻找一个技巧,用
使用条件语句/运算符(''if'',''?''等)使用条件语句/运算符(<'blockquote)来创建最少两个正整数。



我很好奇;为什么你不能使用有条件的?


-

-trent

加入互联网上的数百人!

- 安装OS / 2


Travis Willse< tw ***** @ gladstone.uoregon.edu>写道:

pradt,

以下怎么样?

min(a,b)=(1/2)* abs(a + b) - (1/2)* abs(ab)

请注意,从CS的角度来看,这实际上只是掩盖了运算符abs的定义中的条件
(在大多数
语言,无论如何)。


或更好:min(a,b)=(1/2)*(a + b - abs(ab))


FWIW,替代使用abs将是


min(a,b)=(1/2)*(a + b - Sqrt((ab)^ 2))


David
pr***@yahoo.com 写道:

这可能是一个愚蠢的问题。我正在寻找一个技巧,用
使用条件语句/运算符(''if'',''?''等)使用条件语句/运算符(<'blockquote)来创建最少两个正整数。




This might be a silly question. I''m searching for a trick to
prgramatically find minimum of two positive integers without
using a conditional statement/operator(''if'', ''?'', etc).

解决方案

pradt,

How about the following?

min(a,b)=(1/2)*abs(a+b)-(1/2)*abs(a-b)

Note that from a CS standpoint, this really just buries the conditional
inside the definition of the operator abs (which is predefined in most
languages, anyway).

Cheers,
Travis

pr***@yahoo.com wrote:

This might be a silly question. I''m searching for a trick to
prgramatically find minimum of two positive integers without
using a conditional statement/operator(''if'', ''?'', etc).



Up spake pr***@yahoo.com:

This might be a silly question. I''m searching for a trick to
prgramatically find minimum of two positive integers without
using a conditional statement/operator(''if'', ''?'', etc).



I''m curious; why can''t you use a conditional?

--
-trent
Join the hundreds of people on the Internet!
-- installing OS/2


Travis Willse <tw*****@gladstone.uoregon.edu> wrote:

pradt,

How about the following?

min(a,b)=(1/2)*abs(a+b)-(1/2)*abs(a-b)

Note that from a CS standpoint, this really just buries the conditional
inside the definition of the operator abs (which is predefined in most
languages, anyway).
Or better: min(a,b) = (1/2)*(a + b - abs(a-b))

FWIW, an alternative to using abs would be

min(a,b) = (1/2)*(a + b - Sqrt((a-b)^2))

David
pr***@yahoo.com wrote:

This might be a silly question. I''m searching for a trick to
prgramatically find minimum of two positive integers without
using a conditional statement/operator(''if'', ''?'', etc).



这篇关于如何找到最少两个数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆