Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C locating smallest number


  • Please log in to reply

#1
BTPH

BTPH

    Member

  • Member
  • PipPipPip
  • 167 posts
okay i have 3 different integers; X, Y and Z, the ints are defined by the user, wot i need my program to do is tell the user which int is smallest

ca someone tell me how this is done?

cheers,
ben
  • 0

Advertisements


#2
BuRnEr

BuRnEr

    Member

  • Member
  • PipPip
  • 48 posts
the question is are those 3 numbers input numbers or you defined 3 int variables and intialized them :tazz:?
if it is input from user the answer is obvious isnt it?
like simple way :
you defined only two variables or your way 3 is ok too, you can say array of int, whatever you like
when the first number is entered assigned it the first variable, when the second variable is entered compare them ;
like
is first one is bigger than or smaller than second one in your case just keep small one by assingning it the your first variable(smmaller overwrite the bigger one mean goes garbage), and when the thirth one is enter do same thing (keep small one and throw the bigger one garbage) and than print it?

or defined 3 variables when the user is entered all of them check which is one show smaller one or you can print them asc or desc order...

i m not sure if this little think helps you to solve your problem..
just take care?
BuRnEr
  • 0

#3
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
Can't you just write a small function that checks it directly?

int LeastOf(int x, int y, int z) {
if(x<y && x<z) return x;
if(y<x && y<z) return y;
if(z<x && z<y) return z;
}


Does it need to deal also with the case where two or more of the variables might be equal? In that case you need to add more code.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP