Answer to Question #350363 in C++ for SamV

Question #350363

write a program that prompts the user for the size of an array. The program should then ask the user to enter the numbers into the array. The program should then sort the numbers is ascending order and displays the new sorted numbers


1
Expert's answer
2022-06-13T08:26:15-0400
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int sz;
	cout << "Please, enter the size of an array: ";
	cin >> sz;
	int* arr = new int[sz];
	for (int i = 0; i < sz; i++)
	{
		cout << "Enter "<<i<<" element: ";
		cin >> arr[i];
	}
	sort(&arr[0], &arr[sz]);
	cout << "Sorted array: ";
	for (int i = 0; i < sz; i++)
	{
		cout << arr[i] << " ";
	}
	delete[] arr;
}

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
APPROVED BY CLIENTS