66 999
Assignments Done
99,2%
Successfully Done
In November 2018

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?
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions