Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- /*void fill(int x[], int n);
- int main()
- {
- int x[25];
- int n = 25;
- fill(x, n);
- for (int i = 0; i < n; i++)
- cout << x[i] << " ";
- return 0;
- }
- void fill(int x[], int n)
- {
- srand(time(NULL));
- for (int i = 0; i < n; i++)
- x[i] = (rand() % 28 + (-6));
- }*/
- const int COL = 11;
- const int ROW = 11;
- int matrix[COL][ROW] =
- {
- {1,1,1,1,1,0,1,1,1,1,1},
- {1,1,1,1,0,0,0,1,1,1,1},
- {1,1,1,0,0,0,0,0,1,1,1},
- {1,1,0,0,0,0,0,0,0,1,1},
- {1,0,0,0,0,0,0,0,0,0,1},
- {0,0,0,0,0,0,0,0,0,0,0},
- {1,0,0,0,0,0,0,0,0,0,1},
- {1,1,0,0,0,0,0,0,0,1,1},
- {1,1,1,0,0,0,0,0,1,1,1},
- {1,1,1,1,0,0,0,1,1,1,1},
- {1,1,1,1,1,0,1,1,1,1,1}
- };
- int countOne();
- void swap();
- void printMatrix();
- int main()
- {
- int count = 0;
- count = countOne();
- cout << "Total amount of 1's in the matrix: " << count << endl;
- swap();
- printMatrix();
- return 0;
- }
- int countOne()
- {
- int count = 0;
- for (int row = 0; row < ROW; row++)
- {
- for (int col = 0; col < COL; col++)
- {
- if (matrix[row][col] == 1)
- count++;
- }
- }
- return count;
- }
- void swap()
- {
- for (int row = 0; row < ROW; row++)
- {
- for (int col = 0; col < COL; col++)
- {
- if (matrix[row][col] == 1)
- matrix[row][col] = 0;
- else if (matrix[row][col] == 0)
- matrix[row][col] = 1;
- }
- }
- }
- void printMatrix()
- {
- for (int row = 0; row < ROW; row++)
- {
- for (int col = 0; col < COL; col++)
- {
- cout << matrix[row][col] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement