Ubuntu Forums Archive Viewer

[SOLVED] smallest number from biggest function.

Archived thread 1003608 from Programming Talk. Markdown source: Programming_Talk/thread_1003608_[SOLVED]_smallest_number_from_biggest_function..md

Original URL About this archive
#1

Is it possible to do the following : [PHP]int biggestOfThree( int num1 , int num2 , int num3 ) {

int temp = (num1 > num2) ? num1 : num2; temp = ( temp > num3 ) ? temp : num3;

return temp; }

int smallestOfThree( int num1 , int num2 , int num3 ) {

// use biggestOfThree here to determine the smallest number. // do not use comparison stuff

return num3; } [/PHP]

Need to use biggestOfThree in smallestOfThree , to determine the smallest number without using comparison operators... I dont think its possible. what do u think?

#2

StOoZ said:

what do u think?

Eye wood theenk

  • It's perfectly pointless
  • It can be done
  • It takes more than one call to biggest
#3

Easy:

smallesOfThree(a,b,c) { temp = biggestOfThree(-a,-b,-c); return -temp; }

#4

StOoZ said: Is it possible to do the following :

[PHP]int biggestOfThree( int num1 , int num2 , int num3 ) {

int temp = (num1 > num2) ? num1 : num2; temp = ( temp > num3 ) ? temp : num3;

return temp; }

int smallestOfThree( int num1 , int num2 , int num3 ) {

// use biggestOfThree here to determine the smallest number. // do not use comparison stuff

return num3; } [/PHP]

Need to use biggestOfThree in smallestOfThree , to determine the smallest number without using comparison operators... I dont think its possible. what do u think? Why do you think it is impossible?

#5

Reiger said: Easy:

smallesOfThree(a,b,c) { temp = biggestOfThree(-a,-b,-c); return -temp; }

I hadn't thought of that.

Even shorter:

return -biggestOfThree(-a,-b,-c);
#6

thank you all!! ):P