fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10;
  5.  
  6. int main() {
  7. int size, oddLinesNum, evenLinesNum;
  8. cin >> size >> oddLinesNum >> evenLinesNum;
  9. int mt[MAX_SIZE + 1][MAX_SIZE + 1], oddCurrentEl = 0, evenCurrentEl = 0, number = 1;
  10. for (int line = 1; line <= size; ++line) {
  11. number *= -1;
  12. for (int col = 1; col <= size; ++col) {
  13. /*
  14.   if (line % 2) {
  15.   //mt[line][col] = col * oddLinesNum;
  16.   //cout << (mt[line][col] = col * oddLinesNum) << " ";
  17.   cout << col * oddLinesNum << " ";
  18.   } else {
  19.   //mt[line][col] = (size - (col - 1)) * evenLinesNum;
  20.   //cout << (mt[line][col] = (size - (col - 1)) * evenLinesNum) << " ";
  21.   cout << (size - (col - 1)) * evenLinesNum << " ";
  22.   }
  23.   //cout << mt[line][col] <<" ";
  24.   */
  25. oddCurrentEl = line % 2 * col * oddLinesNum;
  26. evenCurrentEl = (line % 2 + number) * (size - (col - 1)) * evenLinesNum;
  27. mt[line][col] = oddCurrentEl + evenCurrentEl;
  28. cout << mt[line][col] << " ";
  29. }
  30. cout << "\n";
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 5284KB
stdin
7 4 5
stdout
4 8 12 16 20 24 28 
35 30 25 20 15 10 5 
4 8 12 16 20 24 28 
35 30 25 20 15 10 5 
4 8 12 16 20 24 28 
35 30 25 20 15 10 5 
4 8 12 16 20 24 28