Back
Ma_Tran_Xoan_Oc.cpp
Save
// Ma_Tran_Xoan_Oc.cpp #include
using namespace std; void nhap(int &m, int &n) { do { cout<<"Nhap m: "; cin>>m; cout<<"Nhap n: "; cin>>n; if (m < 3 || m > 15 || n < 3 || n > 15) cout<<"\nNhap 3 <= m, n <= 15"; } while (m < 3 || m > 15 || n < 3 || n > 15); } void hien_thi(int a[][15], int m, int n) { int vitri = 0, k = 1; int hang = m-1, cot = n-1; while (k <= m*n) { for (int i = vitri; i <= cot; i++) { a[vitri][i] = k++; } for (int i = vitri+1; i <= hang; i++) { a[i][cot] = k++; } for (int i = cot-1; i >= vitri && k <= m*n; i--) { a[hang][i] = k++; } for (int i = hang-1; i > vitri && k <= m*n; i--) { a[i][vitri] = k++; } vitri++; hang--, cot--; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout<<"\t"<