By Gaby comment asked for a program that:
"Generate 10 random numbers from 0 to 50 and classified in 2 ranges: less than 10 and greater than 10 but less than 20."
Served up to us to practice using random numbers, matrices and cycles.
The program is this:
- For questions regarding the generation of random numbers is this post: Get random numbers in C + + .
- For questions regarding the declaration and use of matrices is this other post: Oh I've never written about arrays!, I'll have to wear it.
- For questions regarding for loops, yes I have a post: Loops in C + + .
We have 3 matrices, the first store our 10 random numbers in the second the numbers remaining in the first classification (less than 10) and the third one left in the second classification. So what we do is go transferring the values of the first array to the other two by value. For this we must carry on the same cycle 3 different accounts, one for each array.
The variable CT1 and CT2 are responsible to go changing indexes and cls2 cls1 matrices respectively, so that should only increase when actually needed.
After all that is necessary is to show our two matrices. Since each parent can have a number of different elements each time, we must do two cycles, one for each ct1 or ct2 matrix limit.
As a final point I only say that, as stated the problem, the number 10 will never be classified as a range because 10 is not less than the 1st and is not greater than 10.
0 comments:
Post a Comment