Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- bool doctep(int a[100], int &n){
- ifstream doc("output.txt");
- if(doc.fail()){
- return false;
- }
- doc >> n;
- for(int i= 0; i <n; i++){
- doc >> a[i];
- }
- return true;
- }
- void doicho(int &x, int & y){
- int tmp = x;
- x = y;
- y = tmp;
- }
- //4 !5 2 8 3
- //2 5 !4 8 3
- //2 3 4 !8 5
- //2 3 4 8 !5
- //2 3 4 5 8
- void sapxepchon(int a[100], int n){
- int csMin;
- for(int i = 0; i < n-1; i++){
- csMin = i;
- for(int j = i+1; j < n; j++){
- if(a[j] < a[csMin]){
- csMin = j;
- }
- }
- if (csMin != i) {
- doicho(a[i], a[csMin]);
- }
- }
- }
- void ghitep(int a[100], int n){
- ofstream ghi("sxepchon.txt");
- ghi << "sap xep chon la: ";
- for(int i = 0 ; i < n; i++) {
- ghi << a[i] << " ";
- }
- }
- int main() {
- int a[100];
- int n;
- if(doctep(a,n)) {
- sapxepchon(a,n);
- ghitep(a,n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement