Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ add two matrix

// C++ program for addition
// of two matrices
#include <bits/stdc++.h>
using namespace std;
#define N 4
 
// This function adds A[][] and B[][], and stores
// the result in C[][]
void add(int A[][N], int B[][N], int C[][N])
{
    int i, j;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            C[i][j] = A[i][j] + B[i][j];
}
 
// Driver code
int main()
{
    int A[N][N] = { {1, 1, 1, 1},
                    {2, 2, 2, 2},
                    {3, 3, 3, 3},
                    {4, 4, 4, 4}};
 
    int B[N][N] = { {1, 1, 1, 1},
                    {2, 2, 2, 2},
                    {3, 3, 3, 3},
                    {4, 4, 4, 4}};
 
    int C[N][N]; // To store result
    int i, j;
    add(A, B, C);
 
    cout << "Result matrix is " << endl;
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        cout << C[i][j] << " ";
        cout << endl;
    }
 
    return 0;
}
 
// This code is contributed by rathbhupendra
Comment

PREVIOUS NEXT
Code Example
Cpp :: factorial function c++ 
Cpp :: how to sort in descending order in c++ 
Cpp :: how to split string in c++ 
Cpp :: who to include a library c++ 
Cpp :: c++ print binary treenode 
Cpp :: palindrome program in c++ 
Cpp :: c++ int to char* 
Cpp :: cout c++ 
Cpp :: How to create files in C++ 
Cpp :: initialize dynamic array c++ to 0 
Cpp :: cpp when use size_t 
Cpp :: cin getline 
Cpp :: how to add external library in clion 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: C++ fill string with random uppercase letters 
Cpp :: remove first occurrence of value from vector c++ 
Cpp :: Search Insert Position leetcode solution in cpp 
Cpp :: c++ hello world linux 
Cpp :: c++ vector remove all duplicate elements 
Cpp :: how to know the number of a certain substring in a string in c++ 
Cpp :: input full line as input in cpp 
Cpp :: convert char to int c++ 
Cpp :: vectors c++ 
Cpp :: c++ changing string to double 
Cpp :: Finding square root without using sqrt function? 
Cpp :: take a function argument 
Cpp :: trie code cpp 
Cpp :: onoverlapbegin ue4 c++ 
Cpp :: c++ unittest in ros 
Cpp :: size of string c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =