
Write a program that, for a matrix entered from the keyboard, calculates the difference between the sum of elements in odd columns and the sum of elements in even rows. The matrix does not have to be square.
#include<iostream>
using namespace std;
int main() {
int a[100][100], n, m, sumCols = 0, sumRows = 0;
cin >> n >> m;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++) {
if ((j + 1) % 2){
sumCols += a[i][j];
}
if (!((i + 1) % 2)){
sumRows += a[i][j];
}
}
}
cout << sumCols - sumRows;
return 0;
}Write a program that, for a matrix entered from the keyboard, replaces the elements of the main diagonal with the difference between the maximum and minimum element in the matrix. Print the resulting matrix to the screen.
#include<iostream>
using namespace std;
int main() {
int a[100][100], n, max, min;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
if (i == 0 && j == 0) {
min = max = a[i][j];
} else if (a[i][j] > max) {
max = a[i][j];
} else if (a[i][j] < min) {
min = a[i][j];
}
}
}
for (int i = 0; i < n; i++) {
a[i][i] = max - min;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << a[i][j] << "\t";
}
cout << endl;
}
return 0;
}Write a program that, for a square matrix entered from the keyboard, prints to the screen whether it is symmetric with respect to the main diagonal.
#include<iostream>
using namespace std;
int main() {
int a[100][100], n, symmetric = 1;
cout << "Enter the dimension of the square matrix:" << endl;
cin >> n;
cout << "Enter the elements:" << endl;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> a[i][j];
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i][j] != a[j][i]) {
symmetric = 0;
break;
}
}
if (!symmetric){
break;
}
}
if (symmetric){
cout << "The matrix is SYMMETRIC with respect to the main diagonal" << endl;
}
else{
cout << "The matrix is not SYMMETRIC with respect to the main diagonal" << endl;
}
return 0;
}It is necessary to find and count all occurrences of the “X” shape composed only of elements with a value of 1. The “X” shape consists of 5 elements with a value of 1 that are appropriately distributed in the matrix (an element with a value of 1 that has elements with a value of 1 as its diagonal neighbors).
The dimensions of a matrix and its elements are entered from the standard input. Count all occurrences of the “X” shape within the matrix. Assume that there should be no overlap of elements from two “X” shapes (example 2). Occurrences of the “X” shape are sought from left to right and top to bottom.
