Advertisement
llvlleo1810

sắp xếp nổi bọt - tháng 4 10, 2018

Apr 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. bool doctep(int a[100], int &n) {
  6.  ifstream Doc("output.txt");
  7.  if(Doc.fail()) {
  8.   return false;
  9.  }
  10.  Doc >> n;
  11.  for(int i = 0; i < n; i++) {
  12.   Doc >> a[i];
  13.  }
  14.  return true;
  15. }
  16.  
  17. int sapxeptang(int a[100], int n) {
  18.  for(int i = 0; i < n-1; i++) {
  19.   for(int j = i+1; j < n ; j++) {
  20.    if( a[i] > a[j]) {
  21.     int tmp = a[i];
  22.     a[i] = a[j];
  23.     a[j] = tmp;
  24.    }
  25.   }
  26.  }
  27.  return 0;
  28. }
  29.  
  30. int ghi( int a[100], int n) {
  31.  ofstream ghi("sapxeptang.txt");
  32.  ghi << "sap xep tang dan la: ";
  33.  for(int i = 0 ; i < n; i++) {
  34.   ghi << a[i] << " ";
  35.  }
  36.  return 0;
  37. }
  38.  
  39. int main() {
  40.  int a[100];
  41.  int n;
  42.  if(doctep(a,n)) {
  43.   sapxeptang(a,n);
  44.   ghi(a,n);
  45.  }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement