{"id":3373,"date":"2019-05-07T13:52:39","date_gmt":"2019-05-07T13:52:39","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3373"},"modified":"2019-05-07T13:52:39","modified_gmt":"2019-05-07T13:52:39","slug":"matrix-programs","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/matrix-programs\/","title":{"rendered":"Matrix Programs"},"content":{"rendered":"<p><strong>Problems<\/strong><\/p>\n<ol>\n<li>Find the Diagonal difference in the Matrix? Add the Diagonal values and subtract them from right to left and left to right? Print the absolute difference as output<\/li>\n<\/ol>\n<p><strong>Solutions<\/strong><\/p>\n<p><strong>Input<\/strong><\/p>\n<pre>\r\n 11  2   4 \r\n 4   5   6\r\n 10  8  -12 \r\n<\/pre>\n<p><strong>Solution<\/strong><\/p>\n<pre>\r\n(11+5+-12)-(4+5+10) \r\n(4)-(19)\r\n(-15)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\n15\r\n<\/pre>\n<p><strong>DiagonalDiff.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass DiagonalDiff\r\n{\r\n public static int difference(int arr&#x5B;]&#x5B;], int n) \r\n {\r\n  int d1 = 0, d2 = 0;\r\n\r\n  for (int i = 0; i &lt; n; i++) \r\n  {\r\n   d1 += arr&#x5B;i]&#x5B;i];\r\n   d2 += arr&#x5B;i]&#x5B;n - i - 1];\r\n  }\r\n  return Math.abs(d1 - d2);\r\n }\r\n \r\n public static void main(String&#x5B;] args) \r\n {\r\n  int n = 3;\r\n\r\n  int arr&#x5B;]&#x5B;] = \r\n  {\r\n   {11, 2, 4}, \r\n   {4 , 5, 6}, \r\n   {10, 8, -12} \r\n  };\r\n\r\n  System.out.print(difference(arr, n));\r\n }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Problems Find the Diagonal difference in the Matrix? Add the Diagonal values and subtract them from right to left and left to right? Print the absolute difference as output Solutions Input 11 2 4 4 5 6 10 8 -12 Solution (11+5+-12)-(4+5+10) (4)-(19) (-15) Output 15 DiagonalDiff.java class DiagonalDiff { public static int difference(int arr&#x5B;]&#x5B;],&hellip; <a href=\"https:\/\/codethataint.com\/blog\/matrix-programs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[278],"tags":[],"class_list":["post-3373","post","type-post","status-publish","format-standard","hentry","category-program-solving"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3373"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3373\/revisions"}],"predecessor-version":[{"id":3374,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3373\/revisions\/3374"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}