Magical Square
Lesson 22 of 25 in Coddy's Coding Problems: Volume 2 course.
We call a square matrix magical if all of its rows and columns have the same sum of elements. You will be given the number of rows and columns N and the matrix itself. Return True and the sum of one row of the matrix if the condition is met, otherwise return False.
Challenge
EasyWrite a program that reads a natural number N from input and following reads N rows of N numbers representing the matrix. Output True if the matrix is magical and the sum of a row, and output False otherwise.
| Input | Output |
|---|---|
| 4
16 23 44 51 32 36 32 34 54 44 13 23 32 31 45 26 | True 134 |
Try it yourself
#include <stdio.h>
int main() {
// Write code here
return 0;
}All lessons in Coding Problems: Volume 2
1Course Introduction
Introduction4Hard Difficulty
Digit SumReverse MatrixVowel PairsMagical SquareHappy SubsequenceTriple DivisionSorting