In: Computer Science
A = [a b c d]
B = [e f g h]
The user will provide the values of a to h.
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: