//ID: 19127640 //Name : Hoang Huu Giap //Bai 8 #include using namespace std; #define M 100 void NhapMang(int a[][M], int& row, int& col) { cout << "Input row:"; cin >> row; cout << "Input col:"; cin >> col; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { cout << "a[" << i << "][" << j << "] ="; cin >> a[i][j]; } cout << endl; } } void XuatMang(int a[][M], int row, int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { cout << a[i][j] << "\t"; } cout << endl; } } void XoayMang(int a[][M], int row, int col) { int temp1 = a[0][0]; int temp2 = a[0][col - 1]; int temp3 = a[row - 1][col - 1]; int temp4 = a[row - 1][1]; for (int i = 0; i < row; i++) //sap xep cot ben ngoai cung { a[i][0] = a[i + 1][0]; } for (int j = col-1; j >= 1; j--) //sap xep dong dau tien { a[0][j] = a[0][j-1]; } for (int i = 1; i < row; i++) //sap xep cot ngoai cung ben phai { a[i + 1][col - 1] = a[i][col - 1]; } for (int j = col-2; j >=1; j--) //sap xep hang cuoi cung sai { a[row -1][j-1]= a[row - 1][j]; } a[0][1] = temp1; a[1][col - 1] = temp2; a[row-1][col-2] = temp3; a[row - 1][0] = temp4; } int main() { int a[M][M], row, col; NhapMang(a, row, col); XuatMang(a, row, col); XoayMang(a, row, col); cout << "Mang sau khi da xoay la:" << endl; XuatMang(a, row, col); return 1; }