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
#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;
}
Comments
Leave a comment