Need help with this program which needs to be done in C++
using namespace std;
int main()
{
int i,j,a,b, first[3][3], second[3][3], sum[3][3], subtract[3][3],
multiply[3][3],scalar,scalarf[3][3],scalars[3][3];
a=b=3;
cout<<"\nEnter the scalar miltiplier:";
cin>>scalar;
cout << "\nEnter the elements of first matrix : ";
for (i=0;i<a;i++ )
{
for (j=0;j<b;j++ )
{
cin >> first[i][j];
}
}
cout << "\nEnter the elements of second matrix:";
for (i= 0 ;i< a ;i++ )
{
for (j= 0;j<b;j++ )
{
cin >> second[i][j];
}
}
for (i=0;i< a;i++ )
{
for (j=0;j<b;j++ )
{
sum[i][j] = first[i][j] + second[i][j];
subtract[i][j] = first[i][j] - second[i][j];
scalarf[i][j]=first[i][j]*scalar;
scalars[i][j]=second[i][j]*scalar;
}
}
for(i = 0; i < a; ++i)
for(j = 0; j < b; ++j)
{
multiply[i][j]=0;
}
// Multiplying matrix a and b and storing in array mult.
for(i = 0; i < a; ++i)
for(j = 0; j < b; ++j)
for(int k = 0; k < a; ++k)
{
multiply[i][j] += first[i][k] * second[k][j];
}
cout << "\nFirst matrix : "<<endl;
for (i=0 ; i < a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << first[i][j] << "\t";
}
cout << endl;
}cout << "\nSecond matrix : "<<endl;
for (i=0 ; i < a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << second[i][j] << "\t";
}
cout << endl;
}
cout << "\nSum of entered matrices : "<<endl;
for (i=0 ; i < a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << sum[i][j] << "\t";
}
cout << endl;
}
cout << "\nSubtraction of entered matrices :
"<<endl;
for (i=0 ; i < a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << subtract[i][j] << "\t";
}
cout << endl;
}
cout << "\nMultiplication of entered matrices :
"<<endl;
for (i=0 ; i <a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << multiply[i][j] << "\t";
}
cout << endl;
}
cout << "\nScalar multiplication of first matrix :
"<<endl;
for (i=0 ; i <a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << scalarf[i][j] << "\t";
}
cout << endl;
}
cout << "\nScalar multiplication of second matrix :
"<<endl;
for (i=0 ; i <a ; i++ )
{
for ( j = 0 ; j < b ; j++ )
{
cout << scalars[i][j] << "\t";
}
cout << endl;
}
return 0;
}
Please upvote... Thanks
Need help with this program which needs to be done in C++ 2 dim arrays as...
3. Write a complete assembly language program to read two matrices (2-dim arrays) A and B and display the resulting matrix C, which is the sum of A and B. Procedures must be used to organize the code.
use Python IDEL Problem 4 Fix a program. This program should calculate the matrix addition (C - A+B, where each element of matrix C is equal to the sum of the elements of matrices A and B that have the same indexes cij - aij + bij). However it is incomplete: the range() function arguments, index values of nested lists A, B, and C, and two list statements are missing. Can you find them and fix the program? What is...
Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
Need help!! 1) Let A, B, C, and D be the matrices defined below. Compute the matrix expressions when they are defined; if an expression is undefined, explain why. [2 0-1] [7 -5 A= .B -5 -4 1 C- ,D= (-5 3] [I -3 a) AB b) CD c) DB d) 3C-D e) A+ 2B 2) Let A and B be the matrices defined below. 4 -2 3) A=-3 0, B= 3 5 a) Compute AB using the definition of...
The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...
You are wanting to communicate secret messages with your friend, and you choose to do this with matrices. The encoding matrix that you choose to use is 2 -2 -1 6 You use the following key to convert your message into a string of numbers, where "O" is used as a placeholder where required. A B C D EF G H IJ K L M 10 2 11 24 19 5 25 20 3 7 16 6 14 N O...
discrete math question 2 i meant question 4 Boolean Algebra and Computer MAT335 T 632 Be 56 matrix addition and 4. Let Ah(Z) denote the set of 2 × 2 matrices with integer entries, and let + denote denote matrix multiplication. Given then A'- Using[0 이andld :] 「0 0 lo 0 as the 0 element and the 1 element, respectively, either prove [(Z,+,, ', 0, 1 is a Boolean algebra or give a reason why it is not. s and...
68 4 64 73 1 5. Matrix C is a coded message where C61 4 52 51 0 109 5 120 170 5 You know that each letter of the original message was first replaced with the number corresponding to its placement in the English alphabet (eg. E was replaced with 5) and any spaces in the message were replaced with zeroes. Then the message was encoded by multiplying the message matrix, M, on the left by the coding matrix,...
I already solved part A and I just need help with part B 1. Matrix Multiplication The product of two n xn matrices X and Y is a third n x n matrix 2 = XY, with entries 2 - 21; = xixYk x k=1 There are n’ entries to compute, each one at a cost of O(n). The formula implies an algorithm with O(nº) running time. For a long time this was widely believed to be the best running...
need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary parts of a complex number }; typedef struct _cplx Complex; // Initializes a complex number from two real numbers Complex CmplxInit(double re, double im) Complex z = { re, im }; return z; // Prints a complex number to the screen void CmplxPrint(Complex z) // Not printing a newline allows this to be printed in the middle of...