Reputation: 3
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int n, k , i, j, mic;
char results[100], read[100];
ifstream averiin;
ofstream averiout("averi.out");
averiin.open("averi.in", ifstream::in);
averiin>>n>>k;
for(i=0;i<n;i++) {
averiin>>read[i];
}
for(i=0;i<n;i++) {
for(j=i+1;j<n;j++) {
if(read[i] > read[j]) {
mic = read[j];
read[j] = read[i];
read[i] = mic;
}
}
}
for(i=0;i<k;i++) {
results[i] = read[i];
averiout<<results[i];
cout<<results[i]<<" ";
}
averiout.close();
getchar();
}
If I want to read for example: 20 12 25 36 2 67, what I need to change to read the 2 character numbers? This code reads one by one... :(
Thanks!
Upvotes: 0
Views: 362
Reputation: 2031
Change the type of read
to array of int's and it should work (results probably also needs to be changed to array of ints).
Upvotes: 1