Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

C++ STL code to input numbers and sort them

#include <iostream>
#include <algorithm>
using namespace std;

bool cmp(int a, int b)
{
    return (a < b);
}

int main()
{
    int num[1000];
    int N;

    while (cin >> N) {
        for (int i = 0; i < N; i++)
            cin >> num[i];

        sort(num, num + N, cmp);

        for (int i = 0; i < N - 1; i++)
            cout << num[i] << " ";

        cout << num[N - 1] << endl;
    }

    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.