V
vim
hi
How to find biggest of three numbers without comaprimg numbers
How to find biggest of three numbers without comaprimg numbers
vim said:hi
How to find biggest of three numbers without comaprimg numbers
vim said:hi
How to find biggest of three numbers without comaprimg numbers
hi
How to find biggest of three numbers without comaprimg numbers
vim said:hi
How to find biggest of three numbers without comaprimg numbers
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));
> }
How to find biggest of three numbers without comaprimg numbers
Oh, well, simply:
max = (a + b + c * 2 + abs(a - b) + abs(a + b - c * 2 + abs(a - b))) / 4;
Dik said:Oh, well, simply:
max = (a + b + c * 2 + abs(a - b) + abs(a + b - c * 2 + abs(a - b))) / 4;
Thanks. Now I have coffee sprayed all over my monitor and keyboard.Eric said:return a>b?a>c?a:c:b>c?b:c;
No comaprisoms were haremd in the comuptatiom of this reslut.
[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 non-sense 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);
}
}
vim said:hi
How to find biggest of three numbers without comaprimg numbers
Jordan said:More risk of overflow, though.
Bart said: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.
Julian said: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)
Jordan said:First, write an algorithm to find the biggest of two numbers without
comparing them.
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 non-sense 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);
}
}
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!
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.
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.