Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Kindly, Use C to write this program DIRECTIONS:- C matMul_provided.c 1 #include 2 #include 3 #include 4 5 int main(int argc, char* argv[]). 6 {

Kindly, Use C to write this program

image text in transcribed

image text in transcribed image text in transcribed image text in transcribed image text in transcribed image text in transcribed

DIRECTIONS:-

image text in transcribed

C matMul_provided.c 1 #include 2 #include 3 #include 4 5 int main(int argc, char* argv[]). 6 { 7 8 FILE* matrix_a_fp = fopen(argv[1], "r"); 9 if (!matrix_a_fp) { 10 perror("fopen failed"); 11 return EXIT_FAILURE; 12 } 13 14 char buff[256]; 15 16 fscanf(matrix_a_fp,"%s", buff); 17 char length_1 = atoi(buff); 18 int** matrix_a = malloc( length_l * sizeof(int*) ); 19 20 fscanf(matrix_a_fp, "%s", buff); 21 char length_m = atoi(buff); 22 for ( unsigned char i=0; i matrix_a_0.txt 1 1 1 Nm 3 4 matrix_a_1.txt x tests > matrix_a_1.txt 1 1 2 4 3 0 2 4 6 4 E matrix_a_2.txt x tests > matrix_a_2.txt 1 2 2 3 60 4 60 INW ou A WNA - 4 2 6 matrix_a_3.txt x tests > matrix_a_3.txt 1 2 Lilin no 2 3 4 3 1 5 matrix_b_0.txt X tests > E matrix_b_0.txt 1 1 2 1 A WNP 3 1 4 Matrix multiplication is a fundamental task in almost every area of computer science, including machine learning and solving scientific problems. You may wish to review the rules of matrix multiplication. Suppose matrix A has size L rows x M columns, matrix B has size M x N, then the matrix multiplication of the two matrices Ax B = C, where matrix C has size L x N. Your task is to write a C program that takes two command line inputs, indicating two files to load. The first file contains matrix A and the second file contains matrix B. For example: ./matmul tests/matrix_a_0.txt tests/matrix_b_0.txt In both of these input files, the format is such that the first line contains the number of rows in the matrix, and the second line contains the number of columns in the matrix. Then, the file continues for several lines, each line corresponding to a row of the input matrix. In each row, the columns of the matrix are listed, each number separated by a space. Your program should load these files and perform matrix multiplication of the two matrices. Then, your program should output L*N number of numbers reading out the elements of the product matrix C in row-major order: first print out the elements in the first row, separated by spaces, followed by printing the elements of the second row, and so forth. C matMul_provided.c 1 #include 2 #include 3 #include 4 5 int main(int argc, char* argv[]). 6 { 7 8 FILE* matrix_a_fp = fopen(argv[1], "r"); 9 if (!matrix_a_fp) { 10 perror("fopen failed"); 11 return EXIT_FAILURE; 12 } 13 14 char buff[256]; 15 16 fscanf(matrix_a_fp,"%s", buff); 17 char length_1 = atoi(buff); 18 int** matrix_a = malloc( length_l * sizeof(int*) ); 19 20 fscanf(matrix_a_fp, "%s", buff); 21 char length_m = atoi(buff); 22 for ( unsigned char i=0; i matrix_a_0.txt 1 1 1 Nm 3 4 matrix_a_1.txt x tests > matrix_a_1.txt 1 1 2 4 3 0 2 4 6 4 E matrix_a_2.txt x tests > matrix_a_2.txt 1 2 2 3 60 4 60 INW ou A WNA - 4 2 6 matrix_a_3.txt x tests > matrix_a_3.txt 1 2 Lilin no 2 3 4 3 1 5 matrix_b_0.txt X tests > E matrix_b_0.txt 1 1 2 1 A WNP 3 1 4 Matrix multiplication is a fundamental task in almost every area of computer science, including machine learning and solving scientific problems. You may wish to review the rules of matrix multiplication. Suppose matrix A has size L rows x M columns, matrix B has size M x N, then the matrix multiplication of the two matrices Ax B = C, where matrix C has size L x N. Your task is to write a C program that takes two command line inputs, indicating two files to load. The first file contains matrix A and the second file contains matrix B. For example: ./matmul tests/matrix_a_0.txt tests/matrix_b_0.txt In both of these input files, the format is such that the first line contains the number of rows in the matrix, and the second line contains the number of columns in the matrix. Then, the file continues for several lines, each line corresponding to a row of the input matrix. In each row, the columns of the matrix are listed, each number separated by a space. Your program should load these files and perform matrix multiplication of the two matrices. Then, your program should output L*N number of numbers reading out the elements of the product matrix C in row-major order: first print out the elements in the first row, separated by spaces, followed by printing the elements of the second row, and so forth

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions