/* Matrix Vector Multiplication Write a C program that multiplies a 2x2 matrix A with a 2x1 column vector x. The result is a 2x1 column vector b. The relevant formulas for calculating the two components of b are shown below. Ax = b <==> | a1 a2 | * | x1 | = | b1 | <==> b1 = a1*x1 + a2*x2 | a3 a4 | | x2 | | b2 | b2 = a3*x1 + a4*x2 In other words, write a C program that takes six values from the user, calculates two values (b1 and b2) according to the above formulas, and then prints the vector b on the screen. The result vector must be printed in a separate function. The vertical bars to the right of the result vector must be aligned. You can assume that the user will only enter integer values in the range -99 to +99 such that the calculated values for b1 and b2 can be printed with three characters or less. ============= START OF SAMPLE RUN ======================= Please enter the four values of matrix A (a1 a2 a3 a4): 3 5 1 -1 Please enter the two values of vector x (x1, x2): -3 1 Vector b, the product of A and x, is therefore: | -4 | | -4 | ============= END OF SAMPLE RUN ======================= ============= START OF SAMPLE RUN ======================= Please enter the four values of matrix A (a1 a2 a3 a4): -12 3 3 1 Please enter the two values of vector x (x1, x2): 3 -1 Vector b, the product of A and x, is therefore: | -39 | | 8 | ============= END OF SAMPLE RUN ======================= */ #include #include void printVector(int b1, int b2) { printf("Vector b, the product of A and x, is therefore:\n"); printf("| %3d |\n", b1); printf("| %3d |\n", b2); } int main(int argc, char* argv[]) { int a1, a2, a3, a4; int x1, x2; int b1, b2; printf("Please enter the four values of matrix A (a1 a2 a3 a4):\n"); scanf("%d %d %d %d", &a1, &a2, &a3, &a4); printf("Please enter the two values of vector x (x1, x2):\n"); scanf("%d %d", &x1, &x2); // calculate b1 = a1*x1 + a2*x2; b2 = a3*x1 + a4*x2; // print the result printVector(b1, b2); // system("pause"); return 0; }