## C Program to Check whether Matrix is Magic Square or Not ?

A square containing integers arranged in an equal number of rows and columns so that the sum of the integers in any row, column, or diagonal is the same. is called magic Square.

A square containing integers arranged in an equal number of rows and columns so that the sum of the integers in any row, column, or diagonal is the same. is called magic Square.

C Program : C Program to Print Square of Each Element of 2D Matrix [crayon-5c68ee533875b926183799/] Output : [crayon-5c68ee5338763786340145/] Explanation : Note 1 :Wherever a macro name occurs in Program the Preprocessor Substitutes the code of the macro at that position. Whenever we use variable name instead of Macro it will throw error.[crayon-5c68ee5338767755516991/]

[crayon-5c68ee5338b20788666374/]

[crayon-5c68ee5338e46595530284/] Output : [crayon-5c68ee5338e4e138365011/] Explanation : Considering above 3x3 matrix -By Observing , it is clear that when i > j Condition is true then and then only we have to add the elements

[crayon-5c68ee53391aa444665510/] Output [crayon-5c68ee53391b2220899196/] Explanation :Considering above 3x3 matrix -By Observing , it is clear that when i < j Condition is true then and then only we have to add the elementsDownload Program : [ Click Here ]

[crayon-5c68ee533952c588065847/] Output : [crayon-5c68ee5339535846338826/] Note : 2-D array needs two nested for loops Keep in mind :One Matrix can be subtracted with another only if the order of both matrices is Equal No of rows of MAT-1 = No of rows of MAT-2 No of col of MAT-1 = No of col of MAT-2 During subtraction b[0][0] is subtracted from a[0][0] and result is stored in c[0][0]We required two 'for loops' (nested) for following Perpose :Accepting Matrix Displaying Matrix Manipulating Matrix Performing Different Operations on Matrix

[crayon-5c68ee53398f4572072875/] Output [crayon-5c68ee53398fe827103416/] Note : 2-D array needs two nested for loops [crayon-5c68ee5339904944634599/]One Matrix can be added with another only if the order of both matrices is Equal No of rows of MAT-1 = No of rows of MAT-2 No of col of MAT-1 = No of col of MAT-2 During addition a[0][0] is added with b[0][0] and result is stored in c[0][0]Special Note : We required two 'for loops' (nested) for following Perpose :Accepting Matrix Displaying Matrix Manipulating Matrix Performing Different Operations on Matrix

[crayon-5c68ee5339ca3133718985/] Output [crayon-5c68ee5339cab401605663/] Explanation :Considering above 3x3 matrix -We have to add a[0][0],a[1][1],a[2][2] By Observing , it is clear that when i = j Condition is true then and then only we have to add the elements

[crayon-5c68ee533a1f7990578147/] Output : [crayon-5c68ee533a1ff218193642/] Note : 2-D array needs two nested for loops

Accessing Array ElementsTo Access Every 2-D Array we requires 2 Subscript variables. i - Refers the Row number j - Refers Column Number a[1][0] refers element belonging to first row and zeroth columnAccept & Print 2x2 Matrix from user [crayon-5c68ee533a54e167402075/] How it Works ?For Every value of row Subscript , the column Subscript incremented from 0 to n-1 columns i.e For Zeroth row it will accept zeroth,first,second column ( a[0][0],a[0][1],a[0][2]) elements In Next Iteration Row number will be incremented by 1 and the column number [...]

Program : Finding Inverse of a 3 X 3 Matrix [crayon-5c68ee533a8c0137507638/] Output : [crayon-5c68ee533a8c9522573854/] Explanation : Suppose we have to find Inverse of - [crayon-5c68ee533a8cd968129338/] Step 1 :Create One Matrix of Size 3 x 6 i.e Create 3 x 3 Matrix and Append 3 x 3 Unit MatrixStep 2 :Factor = a[0][0] Now For First Row : Divide all Elements by Factor ItselfStep 3 :Now Factor = a[1][0] and Apply Following Formula to 2nd Row[crayon-5c68ee533a8d0036840165/]Step 4 :Now Factor = a[2][0] and Apply Following Formula to 3rd Row[crayon-5c68ee533a8d4760912274/]Step 5 [...]

Program : [crayon-5c68ee533ace8607629744/] Steps :[crayon-5c68ee533acf1902776663/] Multiplication is Possible iff - [crayon-5c68ee533acf4040393054/] Resultant Matrix Will of Dimension- [crayon-5c68ee533acf7797571948/]Steps 1 : [crayon-5c68ee533acfa028785135/] Step 2 : [crayon-5c68ee533acfd911794471/] Programmable Implementation : [crayon-5c68ee533ad00747469629/]

© Copyright 2015. All Rights Reserved.