Computer Science Canada how to generate 4 numbers without repetition |
Author: | Blue_angel00 [ Sat Jun 05, 2004 7:44 pm ] |
Post subject: | how to generate 4 numbers without repetition |
hi i'm new to this site and i haven't been doing programming for a while so i really need help. i need to write a program to generate all the possibilities of 4 numbers from 1 to 40 in order and without repetition. the first number has to be smaller than the second number and so on. for example: 1,2,3,4 then next line has to be 1,2,3,5 all the way to 37,38,39,40. if anyone knows how to write this program i would be greatly appreciated. |
Author: | Delos [ Sat Jun 05, 2004 8:06 pm ] |
Post subject: | |
Store the generated numbers temporarily in an array. Each time a new number is generated, check through that array to see if it is already there...if it isn't, then add the next number to it. Otherwise, generate a new number. |
Author: | Cervantes [ Sat Jun 05, 2004 8:09 pm ] | ||
Post subject: | |||
arrays? dude, this isn't that difficullt
all logic 8) |
Author: | Delos [ Sat Jun 05, 2004 8:21 pm ] | ||
Post subject: | |||
Cervantes wrote: arrays? dude, this isn't that difficullt
I really should read the posts more carefully...hehehe. C (40, 4) works.
(I used the real type as opposed to ints as Turing's ints don't go all that high...) |