Created
April 18, 2018 14:58
-
-
Save tienhieuD/e11467a592ebaa674b2da03d3fed2e4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void nhapmang(int a[], int n) { | |
for (int i = 0; i < n; i++) { | |
cout << "Nhap a[" << i << "]="; | |
cin >> a[i]; | |
} | |
} | |
void xuatmang(int a[], int n) { | |
cout << "Mang a[]: "; | |
for (int i = 0; i < n; i++) { | |
cout << a[i] << " "; | |
} | |
cout << endl; | |
} | |
void chen(int a[], int n, int vitricanchen, int socanchen) { | |
for (int i = n; i >= vitricanchen; i--) { | |
a[i] = a[i - 1]; | |
} | |
a[vitricanchen] = socanchen; | |
n++; | |
} | |
int main() { | |
int a[100]; | |
int n; | |
int vt; | |
int socanchen; | |
cout << "\nNhap so phan tu: n="; | |
cin >> n; | |
nhapmang(a, n); | |
cout << "\nXuat mang vua nhap la:\n"; | |
xuatmang(a, n); | |
cout << "\nNhap vao vi tri can chen: vt="; | |
cin >> vt; | |
cout << "\nNhap vao so can chen: socanchen="; | |
cin >> socanchen; | |
chen(a, n, vt, socanchen); | |
xuatmang(a, n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment