⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr0630.cpp

📁 practice c++, it is from the book http://www.amazon.com/Schaums-Outline-Programming-John-Hubbard
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Example 6.30 on page 146
//  Rotating a two-dimensonal array

#include <cassert>   // defines the assert() function
#include <iostream>  // defines the cout object
using namespace std;

const int SIZE=3;
typedef int Matrix[SIZE][SIZE];
void print(Matrix);
void rotate(Matrix);

int main()
{ // tests the rotate() function:
  Matrix m = { 11, 22, 33, 44, 55, 66, 77, 88, 99 };
  print(m);
  rotate(m);
  print(m);
}

void print(Matrix a)
{ for (int i=0; i<SIZE; i++)
  { for (int j=0; j<SIZE; j++)
      cout << a[i][j] << "\t";
    cout << endl;
  }
  cout << endl;
}

void rotate(Matrix m)
{ Matrix temp;
  for (int i=0; i<SIZE; i++)
    for (int j=0; j<SIZE; j++)
      temp[i][j] = m[SIZE-j-1][i];
  for (int i=0; i<SIZE; i++)
    for (int j=0; j<SIZE; j++)
      m[i][j] = temp[i][j];
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -