+ 3
not efficient
I need to create a program that checks whether the integer square matrix 10x10 in size entered from the keyboard is a "magic square", that is, are the sums of the elements of each row, each column and the sum of the elements of each diagonal equal. I had an idea to solve this problem using Boolean variables, but it was unsuccessful. maybe you know how to solve this problem? please help me 🙏 https://code.sololearn.com/cEo5P98P5upB/?ref=app https://code.sololearn.com/cr73AX85p1s2/?ref=app
13 Answers
+ 1
Hi. You can calculate all sums in the same loop. Store sums for rows/columns in 1-dimensional array. Then you can check whether they all are equal by inserting sums into a set(if all inserted elements were equal the set's length will be 1)
+ 1
The same way as the first one. But indexes are slightly more complicated. col, n-1-col
+ 1
Я написал выше "col, n-1-col". 2 - строка, 1 - столбец
0
Hi, thanks for the hint. I tried a different method here. but how do I calculate the sum of the second diagonal /? ..Now I will fix the code here
0
в обратном порядке
0
Может [col, n - col+1], разве нет?
0
А случай col = 0, что тогда будет?
0
И ещё, первый индекс обычно-строка
0
да, это же индексы, точно🤕
0
первый индекс обычно строка?....
0
Не [col][n - 1 - col],
а наоборот [n - 1- col][col]
0
чтобы все по порядку шло🐸хорошо, спасибо
0
Это кстати неправильное решение)))не работает