Saturday, March 31, 2018

Sort Data in File (Id-1532)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1532

Given a file with a set of numbers in a file, write a C++ program to sort the numbers and print them.

Code: C++

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
main() {
    int k;
    vector<int> m;
    ifstream f;
    char n[20];
    cin>>n;
    f.open(n);
    while(!f.eof()) {
        f>>k;
        m.push_back(k);
    }
    sort(m.begin(),m.end());
    for(vector<int>::iterator i=m.begin(); i!=m.end(); i++)
        cout<<*i<<endl;
}

NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

1 comment: