Question

In: Computer Science

Write a C++ program to determine the sum of two 1-D matrices: A = [a b...

  1. Write a C++ program to determine the sum of two 1-D matrices:

A = [a b c d]

B = [e f g h]

The user will provide the values of a to h.

Solutions

Expert Solution

Code:

#include<iostream>
using namespace std;
int main()
{
   int A[4],B[4],i;/*Declaring variables*/
   cout<<"Enter the elements of the 1st 1-D matrix:";
   for(i=0;i<4;i++)
   {
       cin>>A[i];/*Reading first array*/
   }
   cout<<"Enter the elements of the 2nd 1-D matrix:";
   for(i=0;i<4;i++)
   {
       cin>>B[i];/*Reading second array*/
   }
   cout<<"Sum of 2 1-D matrices: ";
   for(i=0;i<4;i++)
   {
       cout<<A[i]+B[i]<<" ";/*Printing the sum of 2 2d matrices*/
   }
  
  
}

Output:

Indentation:


Related Solutions

Write a function that will accept two integer matrices C and D by reference parameters. The...
Write a function that will accept two integer matrices C and D by reference parameters. The function will compute the transpose of C and store it in D. For your information, the transpose of matrix C is D, where D[j][i] = C[i][j]. [7 marks] Explain the time complexity of this function inside of the function code as a comment. [3 marks] in C++
write a c++ program to read two matrices with any size. Your program should have at...
write a c++ program to read two matrices with any size. Your program should have at least the following functions Main() Read a Matrix Add two matrices Subtract two matrices multiply two matrices display a matrice
Write a program in C++ that calculates the sum of two fractions. The program should ask...
Write a program in C++ that calculates the sum of two fractions. The program should ask for the numerators and denominators of two fractions and then output the sum of the two fractions. You will need to write four functions for this program, one to read the inputted data, one to calculate the sum of the two fractions, one to find the Greatest Common Divider (GCD) between the numerator and denominator and a function that will display the end result....
Complete the following program so that C = A*B where A and B are the matrices...
Complete the following program so that C = A*B where A and B are the matrices defined below. N=4; M=3; A=rand(M,N); B=rand(N,M); C = ? for m = 1: M    for n = 1 : ? for p = 1 : ? C (m,n) = ?       end    end end You may upload a script
*****In C++***** Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices...
*****In C++***** Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices must of the same size. The program defines method Addition() that takes two two-dimensional arrays of integers and returns their addition as a two-dimensional array. The program main method defines two 3-by-3 arrays of type integer. The method prompts the user to initialize the arrays. Then it calls method Addition(). Finally, it prints out the array retuned by method Addition(). Document your code, and...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3!...
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3! /3+4! /4+5! /5 using the function1, • to convert decimal number to binary number using the function2, • to check whether a number is a prime number or not using the function3, • to check whether two given strings are an anagram using the function4. important must do in (Multi-Filing) of c++
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers...
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers between a given range (limit your range from 0 to 50). For example, if the user want to add the integers between (and including) 1 and 10, then the program should add: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 Algorithm: Program title/description Ask the user to input a start value in the...
1.            Determine whether the function f from { a, b, c, d } to {a,...
1.            Determine whether the function f from { a, b, c, d } to {a, b, c, d, e} is injective (one-to-one), surjective (onto) and/or bijective (one-to- one correspondence) : f(a) = a,            f(b) = c,            f(c) = b, f(d) = e a. Is this function injective?              . surjective?              . bijective?              . If your answer is no for any of the above, explain:             b. Is there an inverse for this function?              . c. Is the composition f...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT