C++ question - add the two matrices and display the elements of resultant matrix.

C++ question - add the two matrices and display the elements of resultant matrix.

  1. Write a program to accept from user elements of two 2x3 matrices. Then add the two matrices and display the elements of resultant matrix.
View Answers

May 8, 2012 at 3:31 PM

C sum of two matrices

The given code allow the user to enter the number of rows and columns of matrix. Accordingly, the code accepts the row and column values from the user and determine their sum.

#include <stdio.h>
#include <conio.h>

void main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];

   printf("Enter the number of rows and columns of matrix ");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         scanf("%d", &first[c][d]);

   printf("Enter the elements of second matrix\n");

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
            scanf("%d", &second[c][d]);

   for ( c = 0 ; c < m ; c++ )
      for ( d = 0 ; d < n ; d++ )
         sum[c][d] = first[c][d] + second[c][d];

   printf("Sum of entered matrices:-\n");

   for ( c = 0 ; c < m ; c++ )
   {
      for ( d = 0 ; d < n ; d++ )
         printf("%d\t", sum[c][d]);

      printf("\n");
   }
   getch();

}

May 8, 2012 at 3:32 PM

If you another example then please go through the following link:

C Sum of two matrices


May 8, 2012 at 3:35 PM

C++ Sum of matrix

The given code allow the user to enter the number of rows and columns of matrix. Accordingly, the code accepts the row and column values from the user and determine their sum.

#include<iostream>
 #include<stdio.h>
 #include<conio.h>

    using namespace std;

   void main()
    {
       int m, n, c, d, first[10][10], second[10][10], sum[10][10];

       cout << "Enter the number of rows and columns of matrix ";
       cin >> m >> n;
       cout << "Enter the elements of first matrix\n";

       for (  c = 0 ; c < m ; c++ )
          for ( d = 0 ; d < n ; d++ )
             cin >> first[c][d];

       cout << "Enter the elements of second matrix\n";

       for ( c = 0 ; c < m ;c++ )
          for ( d = 0 ; d < n ; d++ )
                cin >> second[c][d];

       for ( c = 0 ; c < m ; c++ )
          for ( d = 0 ; d < n ; d++ )
             sum[c][d] = first[c][d] + second[c][d];

       cout << "Sum of entered matrices:-\n";

       for ( c = 0 ; c < m ; c++ )
       {
          for ( d = 0 ; d < n ; d++ )
             cout << sum[c][d] << "\t";

          cout << endl;
       }

      getch();
    }









Related Tutorials/Questions & Answers:
Write a C language program to read two matrices and multiply them?
Write a C language program to read two matrices and multiply them?  Write a C language program to read two matrices and multiply them?   Here is an example of multiplying two matrices using C language. #include <
C Addition of two matrices
C Addition of two matrices In this section, we are going to calculate the sum of  two 2 X 2 matrices containing rows and columns. For this , we need... to input values for two matrices. To make the matrix of 2 X 2, we are using 
Advertisements
with out using scanner mul two matrices
with out using scanner mul two matrices  write a java program to multiply two matrices and print there result. note: don't use the scanner...]; System.out.println("Enter elements for matrix A : "); for (int i=0 ; i
Matrix multiplication in java
multiplication of two matrices. In java this is a simple program to multiply two matrices... two-dimensional array. Here we are going to develop a Java code for matrices multiplication, while multiplying two matrices the number of column in first
Matrix multiplication
Matrix multiplication  program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication
Java Matrix Subtraction Example
and then accept the matrix elements as array elements. We have declared two... the subtraction of two matrices. Not only, addition and multiplication, you can... between  two matrices of any order. In the given program, firstly we have allowed
Java Matrix Multiplication Example
and then accept the matrix elements as array elements. We have declared two... to multiply two matrices. Like mathematical operations of two numbers, you can... the multiplication of two matrices of any order. In the given program, firstly we have
Java Matrix Addition Example
the sum of two matrices. You may have solved many Matrix Operations in Mathematics... to show in matrices and then accept the matrix elements as array elements. We have declared two 2-dimensional array of integer type to store the matrix elements
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
C# question
C# question  Write a program in C# to create 3*4 matrix and show the sum of diagonal values
C# question
C# question  Write a program in C# to create 3*4 matrix and show the sum of diagonal values
C/C++/JAVA Question on function
C/C++/JAVA Question on function  "Write a function to find out common alphabets between two arrays. Length of array is not fixed and may contain other data type also.ââ?¬Â? Question can be solved in C,C++ or JAVA
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question... and savingsTest.cs to Demonstrate Abstract Classes in C
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10   Ã?¨Ã?±Ã?â? Ã?§Ã?â?¦Ã?¬ Ã?â??Ã?â?¦Ã?¨Ã?§Ã?¯Ã?â??Ã?© Ã?¨Ã
C# question
C# question  Explain enumeration base types in C
C# question
C# question  In C#, string is a class or primitive type. Explain
C# question
C# question  How can we call method pass by reference in C
c question
c question  How to convert decimal numbers into binary digits without using pow function in c language
Sum of two Matrix
Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix... to this. In this program we are going to calculate the sum of two matrix. To make this program
Multiplication of two Matrix
Multiplication of Two Matrix   ... that teaches you the method to multiply two matrix. We are going to make a simple program that will multiply two matrix. Now to make this program run, you need
Multiplication of two Matrix
for multiplying two matrix to each other. Here providing you Java source code... program that will multiply two matrix. Two dimensional array represents the matrix.  Now, make this program, you have to declare two multidimensional array
Dividing of two Matrix in Java
Dividing of two Matrix in Java   ...;Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two matrix. Now we
turbo C Question 6.
turbo C Question 6.  Explain call by value and call by reference with easy examples
turbo C Question 4.
turbo C Question 4.  Possible to print the following (Using for Loops): 1. * ** 2.* * ** * * * *   specify the format properly
turbo C Question 4.
turbo C Question 4.  Possible to print the following (Using for Loops): 1. * ** 2.* * ** * * * *   specify the format properly
Display Common Elements from two ArrayLists in Java
Display Common Elements from two ArrayLists in Java In this section, we are going to compare two array lists and display the common elements from both of them. To show the common elements from the two list, we have created two array
Display Different Elements from two ArrayLists in Java
Display Different Elements from two ArrayLists Java In this section, we are going to compare two array lists and display the different elements from both of them. To show the different elements from the two list, we have created two
C++ Question 2
of these two classes has a member function displayArea()to display the area...C++ Triangle and Rectangle - calculate area of Triangle and rectangle using data members from base class  2.create class. Shape accepts two values
Write a question to display the follwing
Write a question to display the follwing  Write a Java program to display a pattern?   String str = ""; int count = 4; for( int i=9,j...++; } System.out.print(str);   class Display { public void
turbo C Question 5.
turbo C Question 5.  is it possible to print "", 1st line (5 times),2nd line *(4 times),3rd line *(3 times),4th line *(2 times) & 5th line *(1 times) with Align Right. and also reverse order as 1,2,3,4,5 (but right aline
concatenation of Two bytes in C
concatenation of Two bytes in C  Hi, I need to concatenate two bytes array in C.How to do that. bytes[0] = (n >> 24) & 0xFF; bytes[1] = (n >> 16) & 0xFF; bytes[2] = (n >> 8) & 0xFF; bytes[3] = n &
want to display the follwing matrix format - Java Beginners
want to display the follwing matrix format  Hi frends, Actually i was working on the following matrix format........I neeed to use arraylist... gives 3 then he should get 3*3 matrix with folllowing data, and when user gives 4
Matrix Multiplication in Java
Here, we will write a simple program, which will multiply two matrix. A Two... in order to multiply two matrix To initiate with the program, you have... the elements of first matrix"); for ( i = 0 ; i < m ; i
question about mixing two strings
question about mixing two strings  using java script we need to ask two strig and combine them like.. str1= helo str2= worl combined string= hweolrol
Sum of diagonal of Matrix in C
C Sum of diagonal of Matrix In this section, you will learn how to determine the sum of both the diagonal of 3X3 matrix. For this, we have declared an array of integers and using the for loops, we have determined the sum of both
How to Display Duplicate elements from more than one List in java?
that compare two array lists and display the common elements from both of them...How to Display Duplicate elements from more than one List in java?  How to Display Duplicate elements from more than one List in java? //I mean
Need coding help - two dimensional matrix and it returns back a boolean.
Need coding help - two dimensional matrix and it returns back a boolean.  I need to write a code method that accepts a two dimensional integer arrays as the argument and returns true if the array or matrix is left or right
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
C Program for Addtion of 2*2 Diagnol Matrix - Development process
C Program for Addtion of 2*2 Diagnol Matrix   Hello Sir, I want C Program to Do Addtion of Diagnol Matrix in C language. Plz Give Me   Hi...],b[2][2],c[2][2],i,j; clrscr(); printf("Enter the First matrix:\n"); for(i=0
Java, matrix
= new int[2][2]; int[][] C = new int[2][2]; System.out.println("Enter elements for matrix A : "); for (int i=0 ; i < A.length ; i++) for (int j=0 ; j < A[i... of matrix.   Hello Friend, Try this:ADS_TO_REPLACE_1 import
Merge of two arrays in C
;The elements of first array are : \n"); display(a,5); printf("...;The elements of second array are : \n"); display(b,5); sort(a,5...;The elements of merged list is \n"); display(c,10); getch(); } void
how to display duplicate elements with out using collection Frame work?
how to display duplicate elements with out using collection Frame work?  how to display duplicate elements with out using collection Frame work
Square Elements of Two Dimensional Array
_TO_REPLACE_1 We are going to display the square of two matrix. Firstly, we... Square Elements of Two Dimensional Array   ... the two dimensional array program and its square. This session provide you
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
turbo c pre-increment question
turbo c pre-increment question  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
C Program Question - Development process
C Program Question  How i can calulate sum of First digit and last digit of Five Numbers. e.g 12345 i want to calculate 1+5=6 how i can calculate in C Program?   Hi Friend, Try the following code
how can I great two user and password in C++?
how can I great two user and password in C++?  how can I great two user and password in c
how can I great two user and password in C++?
how can I great two user and password in C++?  how can I great two user and password in C
ModuleNotFoundError: No module named 'matrices'
ModuleNotFoundError: No module named 'matrices'  Hi, My Python... 'matrices' How to remove the ModuleNotFoundError: No module named 'matrices... to install padas library. You can install matrices python with following
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose

Ads