Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy this C code below : #include #include #include int main(int argc,char *argv[]) { unsigned char i=0; unsigned char j=0; unsigned char x=0; //read the

Copy this C code below :

#include

#include

#include

int main(int argc,char *argv[])

{

unsigned char i=0;

unsigned char j=0;

unsigned char x=0;

//read the data for first matrix

FILE* matrix_a_fp = fopen(argv[1],"r");

if(!matrix_a_fp)

{

perror("fopen failed");

return EXIT_FAILURE;

}

char buff[256];

fscanf(matrix_a_fp,"%s",buff);

char length_l = atoi(buff);

int ** matrix_a = (int **)malloc(length_l*sizeof(int *));

fscanf(matrix_a_fp,"%s",buff);

char length_m = atoi(buff);

printf("MATRIX 1 ");

for(i=0;i

{

matrix_a[i]=(int *)malloc(length_m*sizeof(int));

for(j=0;j

{

fscanf(matrix_a_fp,"%s",buff);

matrix_a[i][j]=atoi(buff);

printf("%d ",matrix_a[i][j]);

}

printf(" ");

}

//read the data for second matrix

FILE* matrix_a_fp2 = fopen(argv[2],"r");

if(!matrix_a_fp2)

{

perror("fopen failed");

return EXIT_FAILURE;

}

fscanf(matrix_a_fp2,"%s",buff);

char length_l2 = atoi(buff);

int ** matrix_a2 = (int **)malloc(length_l2*sizeof(int *));

fscanf(matrix_a_fp2,"%s",buff);

char length_m2 = atoi(buff);

printf("MATRIX 2 ");

for(i=0;i

{

matrix_a2[i]=(int *)malloc(length_m2*sizeof(int));

//now read the data into the matrix

for(j=0;j

{

fscanf(matrix_a_fp2,"%s",buff);

matrix_a2[i][j]=atoi(buff);

printf("%d ",matrix_a2[i][j]);

}

printf(" ");

}

//after reading the data do matrix multiplication

int ** matrix_res = (int **)malloc(length_l*sizeof(int *));

//if first matrix had dimension MXN

// if second matrix had dimension NXK

//the new matrix will be of dimensions MXK

for(i=0;i

{

//give storage

matrix_res[i]=(int *)malloc(length_m2*sizeof(int));

for( j=0;j

{

matrix_res[i][j]=0; //set to zero

for(x=0;x

{

matrix_res[i][j]+=matrix_a[i][x]*matrix_a2[x][j];

}

}

}

printf("MATRIX MULTIPLICATION RESULT ");

//print the matrix on screen

for( i=0;i

{

for( j=0;j

{

printf("%d ",matrix_res[i][j]);

}

printf(" ");

}

//free all the used memory and close the files

fclose(matrix_a_fp);

for(i=0;i

{

free(matrix_a[i]);

}

free(matrix_a);

fclose(matrix_a_fp2);

for( i=0;i

{

free(matrix_a2[i]);

}

free(matrix_a2);

for( i=0;i

{

free(matrix_res[i]);

}

free(matrix_res);

return 0;

}

YOUR TASK:

This code multiples two matrices and prints its result, your task is to edit this code such that it ONLY outputs the result of two matrix multiplication and NOTHING else.

I DONT NEED IT TO OUTPUT MATRIX 1 VALUES OR MATRIX 2 VALUES NOTHING SHOULD BE PRINTED IN THE CONSOLE EXPECT THE RESULT OF THE MATRIX MULTIPLICATION

Thank you!

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago