## 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-6175797c444c8695334114/] Output : [crayon-6175797c444d1642542022/] 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-6175797c444d5176839834/]

[crayon-6175797c448b1806557705/]

[crayon-6175797c44c1a089198886/] Output : [crayon-6175797c44c23129845241/] 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-6175797c44fc8874626174/] Output [crayon-6175797c44fd4032939635/] 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 Download Program : [ Click Here ]

[crayon-6175797c453b4423826940/] Output : [crayon-6175797c453c3589746545/] 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-6175797c457e6575326785/] Output [crayon-6175797c457f5220205206/] Note : 2-D array needs two nested for loops [crayon-6175797c45800170148399/] 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-6175797c45c17321026665/] Output [crayon-6175797c45c1f727092166/] 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-6175797c45f9c868192445/] Output : [crayon-6175797c45fa4216441400/] Note : 2-D array needs two nested for loops

Accessing Array Elements To 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 column Accept & Print 2x2 Matrix from user [crayon-6175797c46363080969926/] 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-6175797c4671e617677013/] Output : [crayon-6175797c46728330594413/] Explanation : Suppose we have to find Inverse of - [crayon-6175797c4672b384847785/] Step 1 : Create One Matrix of Size 3 x 6 i.e Create 3 x 3 Matrix and Append 3 x 3 Unit Matrix Step 2 : Factor = a[0][0] Now For First Row : Divide all Elements by Factor Itself Step 3 : Now Factor = a[1][0] and Apply Following Formula to 2nd Row [crayon-6175797c4672e109182299/] Step 4 : Now Factor = a[2][0] and Apply Following Formula to 3rd Row [crayon-6175797c46731471704324/] Step 5 [...]

Program : [crayon-6175797c46b94764096458/] Steps : [crayon-6175797c46b9d023393907/] Multiplication is Possible iff - [crayon-6175797c46ba0766694504/] Resultant Matrix Will of Dimension- [crayon-6175797c46ba3866470994/] Steps 1 : [crayon-6175797c46ba6825337197/] Step 2 : [crayon-6175797c46ba9453652458/] Programmable Implementation : [crayon-6175797c46bac682613587/]

© Copyright 2015. All Rights Reserved.