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
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
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.
-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++
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...
Write a c program that prints the final sum of all values from 1 to n...
Write a c program that prints the final sum of all values from 1 to n only when n is a positive value. The program is to print "Poor!" when the final sum is less than 70, print "Good" when the sum is between 71 and 90. or "Great!" when the sum is 91 or better.
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...
Let A = {a, b, c, d} and B = {b, d, e}. Write out all...
Let A = {a, b, c, d} and B = {b, d, e}. Write out all of the elements of the following sets. (a) B ∩ ∅ (b) A ∪ B (c) (A ∩ B) × B (d) P(A\B) (e) {X ∈ P(A) | |X| ≤ 3}
Which of the following are true? (1) The sum of two invertible matrices is invertible (2)...
Which of the following are true? (1) The sum of two invertible matrices is invertible (2) The determinant of the sum is the sum of the determinants (3) The determinant of the inverse is the reciprocal of the determinant (4) An nxn matrix is invertible if and only if its determinant is zero (5) The product of two invertible matrices is invertible (so long as the product is defined) (6) If A is a diagonal 3x3 matrix [a,0,0;0,b,0;0,0,c] then its...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT