+ 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

17th Apr 2020, 4:42 AM
shiryaeva
shiryaeva - avatar
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)
17th Apr 2020, 6:00 AM
Stephan
Stephan - avatar
+ 1
The same way as the first one. But indexes are slightly more complicated. col, n-1-col
17th Apr 2020, 6:11 AM
Stephan
Stephan - avatar
+ 1
Я написал выше "col, n-1-col". 2 - строка, 1 - столбец
17th Apr 2020, 6:14 AM
Stephan
Stephan - avatar
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
17th Apr 2020, 6:09 AM
shiryaeva
shiryaeva - avatar
0
в обратном порядке
17th Apr 2020, 6:12 AM
shiryaeva
shiryaeva - avatar
0
Может [col, n - col+1], разве нет?
17th Apr 2020, 6:22 AM
shiryaeva
shiryaeva - avatar
0
А случай col = 0, что тогда будет?
17th Apr 2020, 6:22 AM
Stephan
Stephan - avatar
0
И ещё, первый индекс обычно-строка
17th Apr 2020, 6:24 AM
Stephan
Stephan - avatar
0
да, это же индексы, точно🤕
17th Apr 2020, 6:29 AM
shiryaeva
shiryaeva - avatar
0
первый индекс обычно строка?....
17th Apr 2020, 6:31 AM
shiryaeva
shiryaeva - avatar
0
Не [col][n - 1 - col], а наоборот [n - 1- col][col]
17th Apr 2020, 6:33 AM
Stephan
Stephan - avatar
0
чтобы все по порядку шло🐸хорошо, спасибо
17th Apr 2020, 6:35 AM
shiryaeva
shiryaeva - avatar
0
Это кстати неправильное решение)))не работает
17th Apr 2020, 10:19 AM
shiryaeva
shiryaeva - avatar