c++ program for matrix addition
C++
#include <iostream>
using namespace std;
int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
cout << "Enter number of rows (between 1 and 100): ";
cin >> r;
cout << "Enter number of columns (between 1 and 100): ";
cin >> c;
cout << endl << "Enter elements of 1st matrix: " << endl;
// Storing elements of first matrix entered by user.
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter element a" << i + 1 << j + 1 << " : ";
cin >> a[i][j];
}
// Storing elements of second matrix entered by user.
cout << endl << "Enter elements of 2nd matrix: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << "Enter element b" << i + 1 << j + 1 << " : ";
cin >> b[i][j];
}
// Adding Two matrices
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
sum[i][j] = a[i][j] + b[i][j];
// Displaying the resultant sum matrix.
cout << endl << "Sum of two matrix is: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << sum[i][j] << " ";
if(j == c - 1)
cout << endl;
}
return 0;
}
Also in C++:
- Title
- vector of string in c++
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- std::iomanip c++
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- how to sort an array according to another array c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- single line if c++
- Category
- C++
- Title
- clear console c++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- how to get a letter from the users string in c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- c++ char to string
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- input a string in c++
- Category
- C++
- Title
- user input c++
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- mkdir boost filesystem
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- coronavirus
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- euler phi gfg
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- run program until ctrl-d c++
- Category
- C++
- Title
- fill c++
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- how to take input in C++ in coding
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- set mimetype validation in mongoose
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- how to type cast quotient of two integers to double with c++
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- arduino delay millis
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- cpp how to create an object of template class
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- arrays in C++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- c++ tutorial
- Category
- C++