You are right. This works only for singe digit numbers.

For multi digit numbers, we have to define some sort of separator. You can read more about it here in this StackOverflow answer

]]>Thank you very much for your comment. I appreciate you spending time to write such detailed feedback.

I have modified the program now. Do check when you get time.

I have lost some \n s when I moved my blog from blogger to WordPress!

]]>Just wanted to suggest a little modification on your program.

In its present form, your code does not check if the sums of the rows(sum1) are equal to sum. Eg. try this one

2 6 3

5 4 3

6 3 7

or

4 8 8

7 5 1

4 2 6

Your program will tell that these matrices are magic matrices, Even though the fact is that they aren’t b/c the sums of the rows is different.

Reason for why this is happening: You used the variable flag to check for the sums of the rows and then again to check for the sums of the column. By doing so you are overwriting the former value of flag by the latter.

Suggested Solution1: use two different flags for the two loops(may be flag1 and flag2) and check if both of them are equal to 1.

Suggested Solution2: use print result and return instead of break inside the two for loops. (I would prefer this one).

Thank you!!!

PS: \n and \t are written as n and t. I hope you can edit them as well.

]]>