Advertisement
vqhien

xóa phần tử trong mảng

Apr 7th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <conio.h>
  3. #include <iostream>
  4. #include <math.h>
  5. #include <stdio.h>
  6. using namespace std;
  7. void main()
  8. {
  9.     int a[50], n, i, k;
  10.     cout << "\nnhap so luong phan tu trong mang: ";
  11.     cin >> n;
  12.     while (n <= 0)
  13.     {
  14.         cout << "n phai lon hon 0, vui long nhap lai: ";
  15.         cin >> n;
  16.     }
  17.     for (i = 1; i <= n; i++)
  18.     {
  19.         cout << "nhap phan tu cua mang: ";
  20.         cin >> a[i];
  21.     }
  22.     cout << "nhap vi tri can xoa: ";
  23.     cin >> k;
  24.     for (i = k; i <= n-1; i++)
  25.     {
  26.         a[i] = a[i + 1];
  27.        
  28.     }
  29.     for (i = 1; i<n; i++)
  30.         cout << a[i] << " ";
  31.  
  32.    
  33.     _getch();
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement