# How to find the random number?

Discussion in 'Mac Programming' started by celia, Sep 27, 2007.

1. ### celia macrumors newbie

Joined:
Jun 24, 2007
#1
Hi,

Here is a problem.

1. A Array has 100 elements. {say, int a[100]}
2. Each of it is filled with a random number. {say, a[1] =99, a[2] = 8, .......}
3. Only one element is filled with zero.

Question: What should be the random number in place of which zero is present?

How to solve this problem? What is the logic?

Thanks

2. ### robbieduncan Moderator emeritus

Joined:
Jul 24, 2002
Location:
London
#2
Unless there are some other rules then the element can contain any number. Did you, perhaps, forget to tell us something important, like, say that each number 1...100 must appear once in one element?

Also this sound more than a little like a homework assignment that you should be figuring out on your own...

3. ### 4409723 Suspended

Joined:
Jun 22, 2001
#3
Definitely sounds like some sort of information is missing. Assuming Robbie's idea is the missing information.

An easy way that would (although probably not the fastest) solve the problem:

1. Take your array and sort it using quicksort or something like that.
2. Traverse it looking for the jump of 2 numbers (or the duplicate).
3. Return the missing/duplicated number.

4. ### MongoTheGeek macrumors 68040

Joined:
Sep 13, 2003
Location:
Its not so much where you are as when you are.
#4
I would say 100

0=00=100

Barring that it doesn't matter since it is all random numbers.