{"id":7017,"date":"2021-08-16T12:21:51","date_gmt":"2021-08-16T06:51:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=7017"},"modified":"2021-11-22T18:39:25","modified_gmt":"2021-11-22T13:09:25","slug":"program-for-addition-of-two-matrices-in-python-cpp","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-addition-of-two-matrices-in-python-cpp\/","title":{"rendered":"Program for addition of two matrices in Python & C++ Programming"},"content":{"rendered":"

In the previous article, we have discussed about\u00a0C++11 Multithreading \u2013 Part 8: std::future , std::promise and Returning values from Thread<\/a>. Let us learn Program for addition of two matrices in C++ Program and Python.<\/p>\n

What is a matrix:<\/strong><\/p>\n

A matrix is a rectangular sequence of numbers divided into columns and rows. A matrix element or entry is a number that appears in a matrix.<\/p>\n

Example:<\/strong><\/p>\n

\"\"<\/p>\n

Above is the matrix which contains 5 rows and 4 columns and having elements from 1 to 20.<\/p>\n

In this order, the dimensions of a matrix indicate the number of rows and columns.<\/p>\n

Here as there are 5 rows and 4 columns it is called as 5*4 matrix.<\/p>\n

What is matrix addition:<\/strong><\/p>\n

Given two matrices of same order(dimensions) then we can easily add the two matrices by doing the sum of corresponding elements in both the matrices.<\/p>\n

Example:<\/strong><\/p>\n

\"\"<\/p>\n

Here Matrix C is matrix addition of the matrices A and B.<\/p>\n

Examples for matrix addition:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Matrix 1  =  [  11  -2    0  ]\r\n                    [   4    8    6  ]\r\nMatrix 2 =   [   5    1   -5  ]\r\n                    [   2    3    0 ]<\/pre>\n

Output:<\/strong><\/p>\n

Printing the sum of matrices : \r\n16 -1 -5\r\n6 11 6<\/pre>\n

Program for matrix Addition<\/h2>\n