Advertisement
Guest User

BaiTapMang12

a guest
Dec 11th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void NhapMang(int A[], int &n, int &x)
  6. {
  7.     cin >> n >> x;
  8.     for (int i=0; i<n; i++)
  9.         cin >> A[i];
  10. }
  11.  
  12. void DeleteX(int A[], int &n, int vtri)
  13. {
  14.     for (int i=vtri; i<n-1; i++)
  15.         A[i] = A[i+1];
  16.     n = n-1;        // Giam so luong phan tu cua mang
  17. }
  18.  
  19. void Process(int A[], int &n, int x)
  20. {
  21.     int i =0;
  22.     while (i<n)
  23.     {
  24.         if (A[i]<x)
  25.         {
  26.             DeleteX(A,n,i);
  27.             i--;                //Vi tri moi cap nhat sau khi xoa A[i]
  28.         }
  29.         i++;
  30.     }
  31.  
  32. }
  33.  
  34. void XuatMang (int A[], int n)
  35. {
  36.     for (int i=0; i<n; i++)
  37.         cout << A[i] << " ";
  38. }
  39.  
  40. int main()
  41. {
  42.     int A[1000];
  43.     int x, n;
  44.     NhapMang(A,n,x);
  45.     Process(A,n,x);
  46.     XuatMang(A,n);
  47.  
  48.     system("pause");
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement