In: Computer Science
In C++
#include<iostream>
using namespace std;
const int NUM = 20;
int main() {
// write code to Declare an integer array of size 20 and assign the array with 20 randomly generated integers in the range [1, 100].
// Shuffle the data in the array so that all numbers smaller than 50 are put before the numbers greater or equal to 50. Note you are not allowed to create any other arrays in the program.
// Write code to print out the shuffled array.
return 0;
}
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int NUM = 20;
int main()
{
int arr[NUM];
srand(time(0));
for (int i = 0; i < NUM; i++)
{
arr[i] = (rand() % (100 - 1 + 1)) + 1;
}
for (int i = 0; i < NUM; i++)
cout << arr[i] << " ";
for (int i = 0; i < NUM; i++)
{
int temp;
if (arr[i] >= 50)
{
for (int j = i + 1; j < NUM; j++)
{
if (arr[j] < 50)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
break;
}
}
}
}
cout << endl;
for (int i = 0; i < NUM; i++)
{
cout << arr[i] << " ";
}
}