Wednesday, September 15, 2010

Number Search

1. Prompt user to enter a number to search for
2. Identify this variable as A
3. Check to see if variable A is equal to the first of the 5 random numbers
4. Repeat step 3 with the 2nd, 3rd, 4th, and 5th possible numbers
5. Display Yes if A matches any of the 5 numbers
6. If A doesn't match any of the 5 then Display no
7. Terminate Program

This will work because it's longest possible trials would be (n) or in this case 5 tests. The program terminates a match is or is not found in the first 5 tests. This means that the solution is finite as well as correct. This is the most efficient way I could find to search for a certain variable in a number sequence.

No comments:

Post a Comment