{"id":11472,"date":"2022-12-29T06:47:10","date_gmt":"2022-12-29T06:47:10","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=11472"},"modified":"2023-05-18T12:27:15","modified_gmt":"2023-05-18T12:27:15","slug":"matrix-multiplication-program-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/","title":{"rendered":"Matrix Multiplication Program in C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\" alt=\"\" \/><\/p>\n<p>Matrix multiplication in C is a fundamental operation that involves multiplying two matrices to produce a resultant matrix. Unlike matrix addition, matrix multiplication has stricter criteria and requires careful handling of rows and columns. In this article, we explore the criteria and method for matrix multiplication and provide a C program for performing the operation. Understanding matrix multiplication is essential for various applications in mathematics and computer science.<\/p>\n<h2>Matrix Multiplication in C<\/h2>\n<p>Matrix multiplication is more complex than matrix addition. Consider the 2 matrices being added as shown below<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812237-Matrix%20Multiplication%20Program%20in%20C1.png\" alt=\"\" \/><\/p>\n<p>So, the matrix addition is pretty simple. If both matrices have the same number of rows and columns, they can be added. This is called the matrix addition rule or matrix addition criteria. They are added by adding their corresponding values.<\/p>\n<p>However, the criteria for multiplying two matrices is not that simple. Consider the two matrices shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812270-Matrix%20Multiplication%20Program%20in%20C2.png\" alt=\"\" \/><\/p>\n<p>So, we have a matrix of size 2\u00d73 i.e. 2 rows and 3 columns and we have another matrix of size 3\u00d73 i.e., 3 rows and 2 columns. These 2 matrices cannot be added as they don\u2019t have the same number of rows and columns. But, what if we say that these matrices can be multiplied?<\/p>\n<p>Yes, in fact, these matrices can be multiplied. The matrix multiplication criteria, or the rule to multiply 2 matrices, are as follows.<\/p>\n<p>For two matrices to be multiplied, the number of columns of the first matrix must be equal to the number of rows of the second matrix, and the resultant matrix will be of the order r1x c2, where r1 is the number of rows of the first matrix and c2 is the number of columns of the second matrix.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812270-Matrix%20Multiplication%20Program%20in%20C3.png\" alt=\"\" \/><\/p>\n<p>So, we have understood the matrix multiplication criteria. However, we still need to understand the method to multiply the matrices. So, let us now study the method to multiply matrices. <\/p>\n<h2>Matrix Multiplication<\/h2>\n<p>Consider the matrices shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812270-Matrix%20Multiplication%20Program%20in%20C4.png\" alt=\"\" \/><\/p>\n<p>So, since the number of columns of the first matrix is equal to the number of rows of the second matrix, these 2 matrices can be multiplied, and the resultant will be of the size row1 x col2 = 2 x 3.<\/p>\n<p>Now, the question is how do I get the answer to multiplication?<br \/>\nFor calculating each element of the resultant matrix, we need to multiply the corresponding rows and columns of the 2 input matrices. For instance, if we need to find the element a12, we will take the first row of the first matrix and the second column of the second matrix and multiply their corresponding elements.<\/p>\n<p>If we take a23, we will take the second row of the first matrix and the third column of the second matrix, and multiply their corresponding elements.<\/p>\n<p>Let us multiply the 2 matrices shown below. The step-by-step multiplication for the calculation of each element of the resultant matrix is as follows.<\/p>\n<p>So, to get the element a11, we will multiply the first row of the first matrix with the first column of the second matrix as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812271-Matrix%20Multiplication%20Program%20in%20C5.png\" alt=\"\" \/><\/p>\n<p>Now, we will calculate the next element i.e. a12. For that, we will multiply the first row of the first matrix with the second column of the second matrix as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812308-Matrix%20Multiplication%20Program%20in%20C6.png\" alt=\"\" \/><\/p>\n<p>Now, we will calculate a13 by multiplying the first row of the first matrix with the third column of the second matrix as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812308-Matrix%20Multiplication%20Program%20in%20C7.png\" alt=\"\" \/><\/p>\n<p>Now, we will find out the value of a21. For that, we multiply the second row of the first matrix with the first column of the second matrix as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812312-Matrix%20Multiplication%20Program%20in%20C8.png\" alt=\"\" \/><\/p>\n<p>Now, to calculate the value of a22, we will multiply the second row of the first matrix with the second column of the second matrix as shown below.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812312-Matrix%20Multiplication%20Program%20in%20C9.png\" alt=\"\" \/><\/p>\n<p>Finally, to calculate the value of a23, we will multiply the second row of the first matrix by the third column of the second matrix.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295812341-Matrix%20Multiplication%20Program%20in%20C10.png\" alt=\"\" \/><\/p>\n<p>So, this is how matrix multiplication takes place. So, now that we have understood the complete procedure of matrix multiplication, let us now write the matrix multiplication program in C.<\/p>\n<h2>Matrix Multiplication Program in C<\/h2>\n<p>The matrix multiplication program in C is shown below.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_11307 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_11307 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_11307 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_11307 .wpsm_nav-tabs > li.active > a, #tab_container_11307 .wpsm_nav-tabs > li.active > a:hover, #tab_container_11307 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_11307 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_11307 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_11307 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_11307 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_11307 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_11307 .wpsm_nav-tabs > li > a:hover , #tab_container_11307 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_11307 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_11307 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_11307 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_11307 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_11307 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_11307 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_11307 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11307 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_11307 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_11307 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_11307 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_11307\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_11307\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_11307_1\" aria-controls=\"tabs_desc_11307_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_11307\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_11307_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\"># include &lt;stdio.h&gt;\r\n# include &lt;stdlib.h&gt;\r\n\r\nvoid input(int arr[][10], int m, int n) {\r\n    int i, j;\r\n    printf(\"&#92;nEnter elements of matrix:&#92;n\");\r\n\r\n    for (i = 0; i &lt; m; ++i) {\r\n        for (j = 0; j &lt; n; ++j) {\r\n            printf(\"Enter elements a%d%d: \", i + 1, j + 1);\r\n            scanf(\"%d\", &amp; arr[i][j]);\r\n        }\r\n    }\r\n}\r\n\r\nvoid display(int arr[][10], int m, int n) {\r\n    int i, j;\r\n    for (i = 0; i &lt; m; i++) {\r\n        for (j = 0; j &lt; n; j++) {\r\n            printf(\"%d\", arr[i][j]);\r\n        }\r\n    }\r\n}\r\n\r\nvoid multiply(int a[][10], int b[][10], int c[][10], int m, int n, int p, int q) {\r\n    int i, j, k;\r\n    for (i = 0; i &lt; m; ++i) {\r\n        for (j = 0; j &lt; q; ++j) {\r\n            c[i][j] = 0;\r\n        }\r\n    }\r\n\r\n    for (i = 0; i &lt; m; ++i) {\r\n        for (j = 0; j &lt; q; ++j) {\r\n            for (k = 0; k &lt; n; ++k) {\r\n                c[i][j] += a[i][k] * b[k][j];\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\n\r\nint main(){\r\n      int m, n, p, q, i, j, k;\r\n    int a[10][10], b[10][10], res[10][10];\r\n\r\n    printf(\"Enter the no of rows and cols of first matrix&#92;n\");\r\n    scanf(\"%d%d\", &amp; m, &amp; n);\r\n    printf(\"Enter the number of rows and cols of the second matrix&#92;n\");\r\n    scanf(\"%d%d\", &amp; p, &amp; q);\r\n\r\n    if (n != p) {\r\n        printf(\"Matrix is incompatible for multiplication&#92;n\");\r\n    } else {\r\n        printf(\"Enter the elements of Matrix-A:&#92;n\");\r\n        for (i = 0; i &lt; m; i++) {\r\n            for (j = 0; j &lt; n; j++) {\r\n                scanf(\"%d\", &amp; a[i][j]);\r\n            }\r\n        }\r\n\r\n        printf(\"Enter the elements of Matrix-B:&#92;n\");\r\n        for (i = 0; i &lt; p; i++) {\r\n            for (j = 0; j &lt; q; j++) {\r\n                scanf(\"%d\", &amp; b[i][j]);\r\n            }\r\n        }\r\n\r\n        for (i = 0; i &lt; m; i++) {\r\n            for (j = 0; j &lt; q; j++) {\r\n                res[i][j] = 0;\r\n                for (k = 0; k &lt; p; k++) {\r\n                    res[i][j] += a[i][k] * b[k][j];\r\n                }\r\n            }\r\n        }\r\n\r\n        printf(\"The product of the two matrices is:-&#92;n\");\r\n\r\n        for (i = 0; i &lt; m; i++) {\r\n            for (j = 0; j &lt; q; j++) {\r\n                printf(\"%d&#92;t\", res[i][j]);\r\n            }\r\n            printf(\"&#92;n\");\r\n        }\r\n    }\r\n\r\n    return 0;\r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_11307 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_11307 a\"),jQuery(\"#tab-content_11307\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h2>Matrix Multiplication Algorithm in C:<\/h2>\n<p>So, we have to replicate the procedure studied above in the code. The algorithm for writing a matrix multiplication program in C is as follows.<\/p>\n<ol>\n<li>Take r1 and c1 input from the user.<\/li>\n<li>Take r1xc1 elements as input from the user. These are the elements of the first matrix.<\/li>\n<li>Take r2 and c2 input from the user.<\/li>\n<li>Take r2xc2 elements as input from the user. These are the elements of the second matrix.<\/li>\n<li>Now check for matrix multiplication criteria i.e. check if c1 equals r2. If they are not equal, print that the matrix multiplication is not possible and exit from the program.<\/li>\n<li>If they are equal, perform matrix multiplication by multiplying each column with the corresponding row to get the corresponding row elements of the resultant matrix.<\/li>\n<li>Print the resultant matrix.<\/li>\n<\/ol>\n<h2>Time Complexity of the Matrix Multiplication Program in C:<\/h2>\n<p>The time complexity of the matrix multiplication program in C is O(n3) for a square matrix or O(m x n x k) for rectangular matrices, where n is the dimension of the square matrix, m is the number of rows of the first matrix, n is the number of columns of the second matrix, and k is the common element, i.e., the number of columns of the first matrix or the number of rows of the second matrix.<\/p>\n<h2>Space Complexity of the Matrix Multiplication Program in C:<\/h2>\n<p>There is no auxiliary space used to multiply the matrices. So, the auxiliary space is O(1). However, we have multiplied the matrices and stored the result in another matrix. So, the output space is O(n2) for the square matrix and O(m x n) for rectangular matrices, where m is the number of rows of the first matrix and n is the number of columns of the second matrix.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nMatrix multiplication in C is a crucial operation in linear algebra, with strict criteria and a method that involves multiplying corresponding rows and columns. Through this article, we have explored the criteria, method, and provided a C program for matrix multiplication. By understanding and implementing this operation, readers can gain a solid foundation in matrix manipulation, essential for various mathematical and computational tasks.<\/p>\n<h2>Frequently Asked Questions (FAQs)<\/h2>\n<p><strong>Q1. Can I perform matrix multiplication in C without using loops?<\/strong><br \/>\n<strong>Ans.<\/strong> No, matrix multiplication inherently requires the use of loops to iterate over the elements of the matrices and perform the necessary calculations.<\/p>\n<p><strong>Q2. What happens if the dimensions of the matrices don&#8217;t meet the multiplication criteria?<\/strong><br \/>\n<strong>Ans.<\/strong> If the number of columns in the first matrix is not equal to the number of rows in the second matrix, matrix multiplication is not possible, and an error message should be displayed.<\/p>\n<p><strong>Q3. Is the order of matrix multiplication important?<\/strong><br \/>\n<strong>Ans.<\/strong> Yes, the order of matrix multiplication matters. Changing the order of multiplication can yield different results. Matrix multiplication is not commutative, unlike matrix addition.<\/p>\n<p><strong>Q4. Are there any special libraries or functions in C for matrix multiplication?<\/strong><br \/>\n<strong>Ans.<\/strong> C does not provide built-in functions specifically for matrix multiplication. However, you can implement matrix multiplication algorithms using loops and basic arithmetic operations.<\/p>\n<p><strong>Q5. What are some real-world applications of matrix multiplication in C?<\/strong><br \/>\n<strong>Ans.<\/strong> Matrix multiplication is widely used in various fields, including computer graphics, scientific computing, data analysis, and machine learning. It plays a crucial role in transformations, simulations, optimization problems, and linear algebraic operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Matrix multiplication in C is a fundamental operation that involves multiplying two matrices to produce a resultant matrix. Unlike matrix addition, matrix multiplication has stricter criteria and requires careful handling of rows and columns. In this article, we explore the criteria and method for matrix multiplication and provide a C program for performing the operation. [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11472","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Matrix Multiplication Program in C<\/title>\n<meta name=\"description\" content=\"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matrix Multiplication Program in C\" \/>\n<meta property=\"og:description\" content=\"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-29T06:47:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-18T12:27:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Matrix Multiplication Program in C\",\"datePublished\":\"2022-12-29T06:47:10+00:00\",\"dateModified\":\"2023-05-18T12:27:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\"},\"wordCount\":1265,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\",\"name\":\"Matrix Multiplication Program in C\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\",\"datePublished\":\"2022-12-29T06:47:10+00:00\",\"dateModified\":\"2023-05-18T12:27:15+00:00\",\"description\":\"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Matrix Multiplication Program in C\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Matrix Multiplication Program in C","description":"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Matrix Multiplication Program in C","og_description":"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.","og_url":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-12-29T06:47:10+00:00","article_modified_time":"2023-05-18T12:27:15+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Matrix Multiplication Program in C","datePublished":"2022-12-29T06:47:10+00:00","dateModified":"2023-05-18T12:27:15+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/"},"wordCount":1265,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/","url":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/","name":"Matrix Multiplication Program in C","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg","datePublished":"2022-12-29T06:47:10+00:00","dateModified":"2023-05-18T12:27:15+00:00","description":"Explaining the concept behind Multiplication of matrix and Program code in C Programming Language. The dry run, algorithm and analysis are also discussed.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1672295811927-Matrix%20Multiplication%20Program%20in%20C.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/matrix-multiplication-program-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Matrix Multiplication Program in C"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=11472"}],"version-history":[{"count":3,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11472\/revisions"}],"predecessor-version":[{"id":16485,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/11472\/revisions\/16485"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=11472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=11472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=11472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}