c++complete and change #include using namespace std; int sumbyrow(int* m, int ncol, int row) { int total = 0; for (int i = 0 i < ncol; i++) { total += m[row * ncol + i]; } return total; } int sumBCol(int* m, int nrow, int ncol, int col) { int total = 0; for (int j = 0; < j nrow; j++) { total += m[j * ncol + col]; } return total; } int sumBYLeftDiag(int* m, int ncol) { int total = 0; for (int i = 0, j = ncol - 1; i < ncol && j >= 0; i++, j--) { total += m[i * ncol + j]; } return total; } bool hasDuplicates(int* m, int row) { int flatArray[row * row]; int k = 0 for (int i = 0; i < row; i++) { for (int j = 0; j < row; j++) { flatArray[k++] = m[i * row + j]; } } for (int i = 0; i < (row * row); i++) { for (int j = i + 1; j < (row * row); j++) { if (flatArray[i] == flatArray[j]) return true; } } return flase; } bool isMagicMatrix(int* m, int nrow, int ncol) { if (hasDuplicate(m, nrow), int ncol{ return false; } if (sumByleftDiag(m, nrow) != sumByRightDiag(m, nrow)) { return false; } for (int i = 0; i < nrow; i++) { if (sumByrow(m, nrow, ncol, i) != sumByCol(m, nrow, ncol, i)) { return false; (change here) } } return true; } int main() { int main m[3][3] = { { 8, 1, 6}, { 3, 5, 2}, { 4, 9, 2}, }; (1) 2 + 5 + 9 == 6 + 5 + 7 (2) 2 + 3 + 6 == 2 + 4 + 7 4 + 5 + 5 == 3 + 5 + 8 7 + 8 + 9 == 6 + 5 + 9 (3) 2 + 5 + 9 == 2 + 4 + 7 * / /* */ int m2[2][2] = { { 2, 3 }, // 0 { 4, 5 } // 0 1 }; /* { 2, 3, 6, 4, 5, 5, 7, 8, 9 } */ /* { 2, 3, 4, 5 } */ int a[2]; int* p = a; check((int*)m1, 3); check((int*)m2, 2); int size = sizeof(*m) / sizeof(int); cout << "SIZE OF MATRIX" "<
c++complete and change
#include <iostream>
using namespace std;
int sumbyrow(int* m, int ncol, int row)
{
int total = 0;
for (int i = 0 i < ncol; i++) {
total += m[row * ncol + i];
}
return total;
}
int sumBCol(int* m, int nrow, int ncol, int col)
{
int total = 0;
for (int j = 0; < j nrow; j++) {
total += m[j * ncol + col];
}
return total;
}
int sumBYLeftDiag(int* m, int ncol)
{
int total = 0;
for (int i = 0, j = ncol - 1; i < ncol && j >= 0; i++, j--) {
total += m[i * ncol + j];
}
return total;
}
bool hasDuplicates(int* m, int row) {
int flatArray[row * row];
int k = 0
for (int i = 0; i < row; i++) {
for (int j = 0; j < row; j++) {
flatArray[k++] = m[i * row + j];
}
}
for (int i = 0; i < (row * row); i++) {
for (int j = i + 1; j < (row * row); j++) {
if (flatArray[i] == flatArray[j])
return true;
}
}
return flase;
}
bool isMagicMatrix(int* m, int nrow, int ncol) {
if (hasDuplicate(m, nrow), int ncol{
return false;
}
if (sumByleftDiag(m, nrow) != sumByRightDiag(m, nrow)) {
return false;
}
for (int i = 0; i < nrow; i++) {
if (sumByrow(m, nrow, ncol, i) != sumByCol(m, nrow, ncol, i)) {
return false;
(change here)
}
}
return true;
}
int main()
{
int main m[3][3] = {
{ 8, 1, 6},
{ 3, 5, 2},
{ 4, 9, 2},
};
(1) 2 + 5 + 9 == 6 + 5 + 7
(2) 2 + 3 + 6 == 2 + 4 + 7
4 + 5 + 5 == 3 + 5 + 8
7 + 8 + 9 == 6 + 5 + 9
(3) 2 + 5 + 9 == 2 + 4 + 7
* /
/*
*/
int m2[2][2] = {
{ 2, 3 }, // 0
{ 4, 5 }
// 0 1
};
/* { 2, 3, 6, 4, 5, 5, 7, 8, 9 } */
/* { 2, 3, 4, 5 } */
int a[2];
int* p = a;
check((int*)m1, 3);
check((int*)m2, 2);
int size = sizeof(*m) / sizeof(int);
cout << "SIZE OF MATRIX" "<<size<<"X"<<size<<endl;
if (isMagicMatrix((int*)m, size, size) == 0{
cout << "NO MAGIC SQUARE";
}
else {
cout << "MAGIC SQUARE";
}
return 0;
}

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









