Answer to Question #290475 in C++ for mark

Question #290475

Listing 102

by CodeChum Admin

We've already made listing an array the easy way, but how about listing and printing the array in reverse order?


Make a program that will input an integer and then using loops, add items on an array/list one by one for the same number of times as that of the first inputted integer. Then, print out the array/list in ascending order. After doing that, print the array again on the next line in reverse order, that is, starting from the last item on the array/list down to the first one, each in separated lines.


Input

The first line contains the size of the array.

The next lines contains the items of the array (integers).

5
1
64
32
2
11

Output

The first line contains the elements of the array printed in ascending order.

The second line contains the elements of the array printed in reversed order.

1·64·32·2·11
11·2·32·64·1
1
Expert's answer
2022-01-26T06:57:28-0500
#include <iostream>
#include <string>
using namespace std;


int main(void){
	int size;
	cin>>size;
	int* numbers = new int[size];
	for (int i = 0; i < size; i++) {
		cin>>numbers[i];
	}
	for (int i = 0; i < size; i++) {
		cout<<numbers[i]<<" ";
	}
	cout<<"\n";
	for (int i = size-1; i >= 0; i--) {
		cout<<numbers[i]<<" ";
	}
	cout<<"\n\n\n\n";


	system("pause");
	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