Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- //def.
- int a[4][4], i, j;
- int b[5];
- //input.
- for (j = 0; j <= 3; j++) {
- for (i = 0; i <= 3; i++) {
- cin >> a[j][i];
- }
- }
- //process.
- cout << "before rotation : ";
- for (j = 0; j <= 3; j++) {
- cout << endl << endl;
- for (i = 0; i <= 3; i++) {
- cout << a[j][i] << "\t";
- }
- }
- for (i = 0; i <= 3; i++) {
- b[i] = a[i][i];
- }//transferring the values to the 1D array
- for (j = 1; j <= 3; j++) {
- for (i = 4; i >= 1; i--) {
- b[i] = b[i - 1];
- }
- b[0] = b[4];
- }//rotate
- for (i = 0; i <= 3; i++) {
- a[i][i] = b[i];
- }//transferring the values to the 2D array
- //print.
- cout << "\nafter rotation : ";
- for (j = 0; j <= 3; j++) {
- cout << endl << endl;
- for (i = 0; i <= 3; i++) {
- cout << a[j][i] << "\t";
- }
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment