Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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