Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void populateMatrix(int m[][10], int n)
- {
- int counter = 1;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- m[i][j] = counter;
- counter++;
- }
- }
- cout << "Matrix populated successfully!" << endl;
- }
- void showMatrix(int m[][10], int n)
- {
- cout << "Matrix display: " << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << m[i][j] << "\t";
- }
- cout << endl;
- }
- }
- int calculate(int m[][10], int n)
- {
- // Check the neighbour values for each element, and if the element is greater than all of them, sum it up
- int sum = 0;
- for (int i = 1; i < n - 1; i++)
- {
- for (int j = 1; j < n - 1; j++)
- {
- }
- }
- return sum;
- }
- int main() {
- int matrix[10][10];
- int n; // Rows and columns, since it's a square matrix
- cout << "Enter the number of rows and columns: ";
- cin >> n;
- populateMatrix(matrix, n);
- showMatrix(matrix, n);
- cout << "The sum of the elements that are greater than all their neighbours is: " << calculate(matrix, n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment