SHARE
TWEET

Untitled

a guest Nov 22nd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <time.h>  
  3.  
  4. using namespace std;
  5.  
  6. /*void fill(int x[], int n);
  7.  
  8. int main()
  9. {
  10.     int x[25];
  11.     int n = 25;
  12.  
  13.     fill(x, n);
  14.  
  15.     for (int i = 0; i < n; i++)
  16.         cout << x[i] << " ";
  17.  
  18.     return 0;
  19. }
  20.  
  21. void fill(int x[], int n)
  22. {
  23.     srand(time(NULL));
  24.     for (int i = 0; i < n; i++)
  25.         x[i] = (rand() % 28 + (-6));
  26. }*/
  27.  
  28. const int COL = 11;
  29. const int ROW = 11;
  30. int matrix[COL][ROW] =
  31. {
  32.     {1,1,1,1,1,0,1,1,1,1,1},
  33.     {1,1,1,1,0,0,0,1,1,1,1},
  34.     {1,1,1,0,0,0,0,0,1,1,1},
  35.     {1,1,0,0,0,0,0,0,0,1,1},
  36.     {1,0,0,0,0,0,0,0,0,0,1},
  37.     {0,0,0,0,0,0,0,0,0,0,0},
  38.     {1,0,0,0,0,0,0,0,0,0,1},
  39.     {1,1,0,0,0,0,0,0,0,1,1},
  40.     {1,1,1,0,0,0,0,0,1,1,1},
  41.     {1,1,1,1,0,0,0,1,1,1,1},
  42.     {1,1,1,1,1,0,1,1,1,1,1}
  43. };
  44.  
  45. int countOne();
  46. void swap();
  47. void printMatrix();
  48.  
  49. int main()
  50. {
  51.     int count = 0;
  52.     count = countOne();
  53.     cout << "Total amount of 1's in the matrix: " << count << endl;
  54.  
  55.     swap();
  56.     printMatrix();
  57.  
  58.     return 0;
  59. }
  60.  
  61. int countOne()
  62. {
  63.     int count = 0;
  64.     for (int row = 0; row < ROW; row++)
  65.     {
  66.         for (int col = 0; col < COL; col++)
  67.         {
  68.             if (matrix[row][col] == 1)
  69.                 count++;
  70.         }
  71.     }
  72.  
  73.     return count;
  74. }
  75.  
  76. void swap()
  77. {
  78.     for (int row = 0; row < ROW; row++)
  79.     {
  80.         for (int col = 0; col < COL; col++)
  81.         {
  82.             if (matrix[row][col] == 1)
  83.                 matrix[row][col] = 0;
  84.             else if (matrix[row][col] == 0)
  85.                 matrix[row][col] = 1;
  86.         }
  87.     }
  88. }
  89.  
  90. void printMatrix()
  91. {
  92.     for (int row = 0; row < ROW; row++)
  93.     {
  94.         for (int col = 0; col < COL; col++)
  95.         {
  96.             cout << matrix[row][col] << " ";
  97.         }
  98.  
  99.         cout << endl;
  100.     }
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top