Created
January 9, 2022 22:56
-
-
Save mohshbool/09e1341ee9304105bead8d1bdba19d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int ROW_SIZE = 3; | |
const int COLUMN_SIZE = 3; | |
void CheckMatrix(int m[][COLUMN_SIZE], int ROW_SIZE) | |
{ | |
if (COLUMN_SIZE != ROW_SIZE) | |
{ | |
cout << "NONE"; | |
return; | |
} | |
int i, j; | |
int allEle = m[0][0]; | |
int allSame = 1; | |
for (i = 0; i < ROW_SIZE; i++) | |
{ | |
for (j = 0; j < ROW_SIZE; j++) | |
{ | |
if (m[i][j] != 0 && i != j) | |
{ | |
cout << "0" << endl; | |
return; | |
} | |
else if (m[i][j] != 0 && allEle != m[i][j]) | |
{ | |
allSame = 0; | |
} | |
} | |
} | |
cout << "1" << endl; | |
if (allSame) | |
{ | |
cout << "1" << endl; | |
} | |
else | |
{ | |
cout << "0" << endl; | |
} | |
if (allEle == 1) | |
{ | |
cout << "1" << endl; | |
} | |
else | |
{ | |
cout << "0" << endl; | |
} | |
} | |
int main() | |
{ | |
int mat[ROW_SIZE][COLUMN_SIZE] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; | |
CheckMatrix(mat, ROW_SIZE); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment