fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, mat[100][100] = {0}, b, c;
  6. cin >> n >> b >> c;
  7. for (int i = 1; i <= n; ++i) {
  8. int p = b;
  9. for (int j = 1; j <= n; ++j) {
  10. if (i % 2 == 0) { // Even rows
  11. mat[i][j] = n * c - (j - 1) * c;
  12. } else { // Odd rows
  13. mat[i][j] = p;
  14. p += b;
  15. }
  16. cout << mat[i][j] << " ";
  17. }
  18. cout << "\n";
  19. }
  20. /*
  21. for (int i = 1; i <= n; ++i) {
  22. for (int j = 1; j <= n; ++j) {
  23. cout << mat[i][j] << " ";
  24. }
  25. cout << "\n";
  26. } */
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 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