Answer to Question #336144 in C++ for Array 4.1

Question #336144



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}

1
Expert's answer
2022-05-01T19:05:41-0400
#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;
}

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