-
-
Save anonymous/a8c0dcc070df2b35c31b 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 ORDER = 4; | |
void fill (int m[], int order); | |
void outputMatrix (int m[], int order); | |
void replaceValue (int m[], int n, int row, int column); | |
void numberAllowed (int m[], int order, int n, int row, int column); | |
bool checkRow (int m[], int order, int n, int row); | |
bool checkColumn (int m[], int order, int n, int column); | |
int main(){ | |
int matrix[ORDER]; | |
int row; | |
int column; | |
int n; | |
fill (matrix, ORDER); | |
outputMatrix (matrix, ORDER); | |
do { | |
cout << "Enter the number to place, the row and the column, each separated by a space: "; | |
cin >> n; | |
cin >> row; | |
cin >> column; | |
if (n <= 0 || n > ORDER){ | |
cout << "Thank you"; | |
cout << endl; | |
} | |
replaceValue (matrix, n, row, column); | |
}while (n > 0 && n <= ORDER); | |
return 0; | |
} | |
void fill (int m[], int order){ | |
for (int i = 0; i < order*order; i++){ | |
m[i] = 0; | |
} | |
} | |
void outputMatrix (int m[], int order){ | |
int c = 0; | |
for (int i = 0; i < order*order; i++){ | |
c++; | |
cout << m[i] << ' '; | |
if (c == order){ | |
cout << endl; | |
c = 0; | |
} | |
} | |
cout << endl; | |
} | |
void replaceValue (int m[], int n, int row, int column){ | |
int i; | |
i = row * ORDER + column; | |
m[i] = n; | |
numberAllowed (m, ORDER, n, row, column); | |
} | |
void numberAllowed (int m[], int order, int n, int row, int column){ | |
if (checkRow (m, order, n, row) == true && checkColumn (m, order, n, column) == true){ | |
outputMatrix (m, order); | |
} | |
else if (checkRow (m, order, n, row) == false && checkColumn (m, order, n, column) == false){ | |
cout << "Number not allowed" << endl; | |
} | |
} | |
bool checkRow (int m[], int order, int n, int row){ | |
for (int i = 0; i < order; i++){ | |
if (m[order] * i * row == n){ | |
} | |
} | |
else{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment