fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define MAX 20
  4. void Nhap(int [], int &);
  5. void Xuat(int [], int );
  6. void TronMang(int a[], int b[],int c[], int n);
  7. int main()
  8. {
  9. int n=0;
  10. int a[MAX], b[MAX], c[MAX];
  11. cout << "Nhap so phan tu cua mang (n): ";
  12. cin >> n;
  13. cout << "Mang a: \n";
  14. Nhap(a, n);
  15. Xuat(a, n);
  16. cout << "Mang b: \n";
  17. Nhap(b, n);
  18. Xuat(b, n);
  19. TronMang(a, b,c,n);
  20. cout << "Mang moi la: \n";
  21. Xuat(c, n);
  22. return 0;
  23. }
  24. void Nhap(int a[], int &n)
  25. {
  26. for (int i = 0; i < n; i++)
  27. {
  28. cout << "Phan tu thu "<<i<<" = ";
  29. cin >> a[i];
  30. }
  31. }
  32. void Xuat(int a[], int n)
  33. {
  34. cout << "--- CAC PHAN TU HIEN CO TRONG MANG ---\n";
  35. for (int i = 0; i < n; i++)
  36. {
  37. cout << a[i] << " ";
  38. }
  39. cout << endl;
  40. }
  41. void TronMang(int a[], int b[],int c[], int n)
  42. {
  43. for (int i = 0; i < n; i++)
  44. {
  45. c[i] = a[i] + b[i];
  46. }
  47. }
Success #stdin #stdout 0s 5428KB
stdin
Standard input is empty
stdout
Nhap so phan tu cua mang (n): Mang a: 
--- CAC PHAN TU HIEN CO TRONG MANG ---

Mang b: 
--- CAC PHAN TU HIEN CO TRONG MANG ---

Mang moi la: 
--- CAC PHAN TU HIEN CO TRONG MANG ---