Advertisement
wintest

МАТРИЦА: Шахматна дъска

Jan 15th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <ctime>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. #define M 5
  9. #define N 5
  10.  
  11. void fillTheArray(int array[][N], size_t rows);
  12. void printTheArray(int array[][N], size_t rows);
  13.  
  14. int main(){
  15.     setlocale(LC_ALL, "Bulgarian");
  16.     srand(time(NULL));
  17.  
  18.     int array[M][N];
  19.     fillTheArray(array, M);
  20.     printTheArray(array, M);
  21.     cout << endl;
  22.    
  23.     return 0;
  24. }
  25. //да се запълни матрица с 1 и 0 по шахматна дъска;
  26.  
  27.  
  28. void fillTheArray(int array[][N], size_t rows){
  29.     for (size_t i = 0; i < M; i++)
  30.     {
  31.         if (i % 2 == 0){
  32.             for (size_t j = 0; j < N; j++){
  33.                 if (j % 2 == 0)array[i][j] = 0;
  34.                 else array[i][j] = 1;
  35.             }
  36.         }
  37.         else{
  38.             for (size_t j = 0; j < N; j++){
  39.                 if (j % 2 == 0)array[i][j] = 1;
  40.                 else array[i][j] = 0;
  41.             }
  42.         }
  43.     }
  44. }
  45. //принтирам масив
  46. void printTheArray(int array[][N], size_t rows){
  47.     cout << "Оригиналната матрица е това : " << endl;
  48.  
  49.     for (size_t i = 0; i < M; i++)
  50.     {
  51.         for (size_t j = 0; j < N; j++){
  52.             cout << array[i][j] << "\t";
  53.         }
  54.         cout << endl;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement