Answer to Question #652 in C# for Ram F

Question #652
I managed to create a random number generator, which generates 100 numbers from -20 to 20.
But now i need to rearrange them in a way that the positive numbers will be presented first, then the zeros, and then the negative numbers.
Step 1 is to generate the random numbers (which I managed to do) and step 2 is to press any key (ReadKey) and then the numbers will be rearranged in the way I just wrote about. How do i that?
1
Expert's answer
2010-09-20T10:07:29-0400
First of all, fill the array [0..99] with the generated random numbers.
Then use ReadKey to assume that key was pressed.
After the key has been pressed, use "bubble sorting", the pseudocode is following:
int temp;
for (int i = 0; i < 99; i++) {
for (int i = 0; i < 99; i++) {
if (your_array[i] < your_array[i + 1]) {
temp = your_array[i];
your_array[i] = your_array[i + 1];
your_array[i + 1] = temp;
}
}
}

After the sorting, just output your array, and the positive numbers will be presented first, then the zeros, and then the negative numbers.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS