Advertisement
huutho_96

Array

Dec 2nd, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void nhap_mang(int a[], int &n)
  5. {
  6.     cout << "Nhap so phan tu cua mang: ";
  7.     cin >> n;
  8.     for (int i = 0; i < n; i++)
  9.     {
  10.         cout << "Nhap phan tu arr[" << i + 1 << "] = ";
  11.         cin >> a[i];
  12.     }
  13. }
  14.  
  15. void xuat_mang(int a[], int n)
  16. {
  17.     for (int i = 0; i < n; i++)
  18.         cout << "arr[" << i + 1 << "] = " << a[i] << endl;
  19. }
  20.  
  21. void liet_ke(int a[], int n, int k)
  22. {
  23.     for (int i = 0; i < n; i++)
  24.     if (a[i] == k)
  25.         cout << i << "\t";
  26. }
  27.  
  28. void nhap_mang_2c(int a[][100], int &n, int &m)
  29. {
  30.     cout << "Nhap n: ";
  31.     cin >> n;
  32.     cout << "Nhap m: ";
  33.     cin >> m;
  34.  
  35.     for (int i = 0; i < m; i++)
  36.     {
  37.         for (int j = 0; j < n; j++)
  38.         {
  39.             cout << "arr[" << i << "][" << j << "] = ";
  40.             cin >> a[i][j];
  41.         }
  42.     }
  43. }
  44.  
  45.  
  46. void xuat_mang_2c(int a[][100], int n, int m)
  47. {
  48.     for (int i = 0; i < m; i++)
  49.     {
  50.         for (int j = 0; j < n; j++)
  51.         {
  52.             cout << a[i][j] << "\t";
  53.         }
  54.         cout << "\n";
  55.     }
  56. }
  57.  
  58. void main()
  59. {
  60.     // khai bao mang a kieu int kich thuoc la 1000
  61.     int arr[1000];
  62.     // khai bao mang 2 chieu
  63.     int arr2[100][100];
  64.     // chi so mang trong c danh tu 0 di
  65.     // n - 1 la chi so phan tu cuoi cung
  66.  
  67.     int n, m;
  68.  
  69.     nhap_mang_2c(arr2, n, m);
  70.     xuat_mang_2c(arr2, n, m);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement