Examples:
Input:
arr[ ] = {10, 5,6, 3, 9, 7,4, 1, 2, 8}
Output:
arr[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
// Function to print the array
void printArray(int array[], int n)
{
for (int i = 0; i < n; i++)
cout << array[i] << " ";
cout << endl;
}
// Main function
int main()
{
int array[100], N;
cout << "Enter Number of elements: ";
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> array[i];
}
// sorting the array
sort(array, array + N);
cout << "Sorted Array" << endl;
printArray(array, N);
return 0;
}
Output:
Enter Number of elements: 5
4 6 2 3 7
Sorted Array
2 3 4 6 7
0 Comments