Home Answers Viewqa Hibernate C++ question - add the two matrices and display the elements of resultant matrix.

 
 


Azim Ajmeri
C++ question - add the two matrices and display the elements of resultant matrix.
3 Answer(s)      a year ago
Posted in : Hibernate

  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 Pages:
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 <
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
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 
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
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 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
Java, matrix
]; int[][] C = new int[2][2]; System.out.println("Enter elements for matrix...++){ A[i][j] = input.nextInt(); } System.out.println("Enter elements for matrix B... of 2 matrices*"); for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ C[i][j
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++ 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
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
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
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   Ã?¨Ã?±Ã?â? Ã?§Ã?â?¦Ã?¬ Ã?â??Ã?â?¦Ã?¨Ã?§Ã?¯Ã?â??Ã?© Ã?¨Ã
Square Elements of Two Dimensional Array
: We are going to display the square of two matrix. Firstly, we have to define... Square Elements of Two Dimensional Array   ... the two dimensional array program and its square. This session provide you
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
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
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
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
transpose matrix
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 of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once
The BCG Matrix
The BCG matrix also called the Growth share matrix, B-Box, B.C.G. analysis, Boston Box, Boston Matrix, Boston Consulting Group analysis, portfolio diagram... business units and product lines. In broader terms of management, the BCG matrix
Java create Identity matrix
elements are zeros. Here, we are going to create the unit matrix of arbitrary... and display the matrix of  n x n. Suppose, n is 3, then the unit matrix of size 3 x...Java create Identity matrix In this tutorial, you will learn how to create
question
question  Good Morning Sir, i have two frames client and server .server have two button search and send with one text field and client have one... to display the file chooser and i want to display the selected file on the text field
question
question  Sir, If i have a frame with two button sign in and cancell using java swing .If i am clicking a sign in button using user name and password then i want to display the new client window and if i am clicking cancell
Summary - Basic Elements
Java: Summary - Basic Elements In this section we will learn about commenting... types in Java. c) Code commenting in Java d) Integer types in Java e) Keywords... Types are divided into two categories. There are 8 primitive types
Find Sum of Diagonals of Matrix
) of the matrix from the given two dimensional array. See the following matrix...Find Sum of Diagonals of Matrix You all know that a matrix is a rectangular array of numbers and these numbers in the matrix are called its entries or its
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
C and C++ books-page4
An array in C is a region of memory in which the elements (chars, ints, etc.) can... display something on the screen. Therefore C uses external commands... C and C++ books-page4      
help with substring in c programing
help with substring in c programing  Hi I could not found programming in C in the "select category" so I am posting my question in java section. Please help with substring function,prompt the user for two strings and display
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
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
java list program for common elements
collections list which takes two array list elements and display common elements in both the list as an output   Please visit the following link: Display Common Elements from two ArrayLists
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
C and C++ books-page6
C and C++ books-page6       The Refactoring C++ Code  The two functions DOMString.transcode... a char * (an old-fashioned C string) and in the second case a zero-terminated array
Question on javascript
Question on javascript  There will be two combo box in HTML form.If... Array("B"); arr[3] = new Array("C"); arr[4] = new Array("D"); function change(combo1){ var comboValue = combo1.value; document.forms["form"].elements["combo2
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
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
Addition of two arrays element in C
; for(j=0;j<i;j++) scanf(" %d",&c[j]); } void display...() { void read(int *,int); void display(int *,int); void addarray(int * ,int *,int * ,int); int a[5],b[5],c[5],i; clrscr(); printf("Enter
finding the eigenvalues and eigenvector of n*n matrix in java
finding the eigenvalues and eigenvector of n*n matrix in java  Here...[][] {{4,3,1,2},{1,1,1,1},{1,2,1,1},{1,1,1,1} }; double t, c, s; int p, q, icount... = new double[2][2]; // makes V into a unit matrix V = new double[size][size
two dimensional - Java Beginners
(); matrix = new int[rows][cols]; System.out.println("Enter elements...two dimensional  write a program to create a 3*3 array and print... code: import java.io.*; import java.util.*; public class matrix
HTML Elements
HTML Elements In this session, you will learn more things on HTML. You will learn about the uses of some elements in HTML with a description..., in an unordered list, two main attributes are used, viz., ID and TYPE
Array Implementation in C
are : \n"); display(size,5); } void read(int c[],int i) { int j...Array Implementation in C Code: #include<stdio.h> #include<conio.h> void main() { void read(int *,int); void display(int *,int); int
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
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 &
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.