Instructions:
1. Input a random positive integer. Then, create an integer array with a size the same as the inputted integer.
2. Then, using loops, add random integer values into the array one by one. The number of values to be stored is dependent on the inputted odd integer on the first instruction.
3. Print out the list's new order in this manner, with each number separated by a space per row:
second-half values
middle value
first-half values
Refer to the sample output for a clearer view on how it is to be printed out.
Input
The first line contains an odd positive integer. It is guaranteed that this integer is greater than or equal to 3.
The next lines contains an integer.
5
1
3
4
5
2
Output
A line containing grouped arrays.
{2,5}-{4}-{3,1}
#include <iostream>
using namespace std;
int main()
{
int i = 0, n;
cout << "Enter the number of random numbers: ";
cin >> n;
int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
cout << "{";
for (i = n-1; i >= 0; i--) {
if (i == n/2)
cout << "}-{" << arr[i]<< "}-{" ;
else{
if (i == 0)
cout << arr[i];
else
if (i == n/2+1)
cout << arr[i];
else
cout << arr[i] << ",";
}
}
cout << "}";
return 0;
}
Comments
Leave a comment