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
*****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...
-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...
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}
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT