This should be solved in the matrix.cpp file. Write a program which .docx

K

This should be solved in the matrix.cpp file. Write a program which .docx

This should be solved in the matrix.cpp file. Write a program
which multiplies two matrices. The matrices may be any size,
contain integers, and will come as input from the user. Each
matrix will be input with the columns separated by spaces and
the rows each on a new line. The end of each matrix will be
specified by an empty line with no integers. Your program
should print the resulting matrix with each column separated by
a space, and each row on a new line. Remember that the matrix
product is defined as: (AB)_jf = sum of (A_ik * B_kj) for k = 1
to m (where m is the number of columns in A) Your program
should output an error if the dimensions of the input matrices
are incompatible (the number of columns in the first is not equal
to the number of rows in the second). Each input matrix should
be stored in a multidimensional integer array. You may also
want to use a multidimensional array to store the result matrix.
All three matrices have sizes less or equal 10 by 10. The
program should print a string of text to the terminal before
getting input from the user. A session should look like one of
the following examples (including whitespace and formatting),
with a possibly matrix in the output: Enter first matrix: 1 2 3 m
Enter second matrix: 7 8 9 0 1 2 The product is: 28 14 79 44
Enter first matrix: 12 3 Enter second matrix: 4 5 6 The two
matrices have incompatible dimensions. Each string printed by
the program should include a newline at the end. but no other
trailing whitespace.
Solution
int main(){
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
printf(" Enter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf(" Enter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o){
printf("Matrix mutiplication is not possible");
printf(" Column of first matrix must be same as row of second
matrix");
}
else{
printf(" Enter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf(" Enter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf(" The First matrix is ");
for(i=0;i<m;i++){
printf(" ");
for(j=0;j<n;j++){
printf("%dt",a[i][j]);
}
}
printf(" The Second matrix is ");
for(i=0;i<o;i++){
printf(" ");
for(j=0;j<p;j++){
printf("%dt",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++){ //row of first matrix
for(j=0;j<p;j++){ //column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf(" The multiplication of two matrix is ");
for(i=0;i<m;i++){
printf(" ");
for(j=0;j<p;j++){
printf("%dt",c[i][j]);
}
}
return 0;
}

Más contenido relacionado

Similar a This should be solved in the matrix.cpp file. Write a program which .docx

Mmc manualMmc manual
Mmc manualUrvi Surat
1.1K views61 Folien
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arraysenidcruz
343 views3 Folien

Similar a This should be solved in the matrix.cpp file. Write a program which .docx(20)

Mmc manualMmc manual
Mmc manual
Urvi Surat1.1K views
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arrays
enidcruz343 views
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
Amairullah Khan Lodhi402 views
Signals And Systems Lab Manual, R18 BatchSignals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 Batch
Amairullah Khan Lodhi565 views
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
MugdhaSharma1129 views
Matlab-3.pptxMatlab-3.pptx
Matlab-3.pptx
aboma2hawi2 views
Format stringFormat string
Format string
Vu Review59 views
L03varsL03vars
L03vars
Ramasamyvelambaal Acadamy85 views
A01A01
A01
lksoo368 views
Matlab1Matlab1
Matlab1
guest8ba004914 views
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj1.9K views
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy2.9K views
Cse cpl manual-2016Cse cpl manual-2016
Cse cpl manual-2016
Rajendra khatana376 views
Matlab bookletMatlab booklet
Matlab booklet
Sourabh Bhattacharya669 views
C programming part4C programming part4
C programming part4
Keroles karam khalil343 views

Más de Komlin1(20)

Último(20)

STYP infopack.pdfSTYP infopack.pdf
STYP infopack.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego143 views
Material del tarjetero LEES Travesías.docxMaterial del tarjetero LEES Travesías.docx
Material del tarjetero LEES Travesías.docx
Norberto Millán Muñoz57 views
Sociology KS5Sociology KS5
Sociology KS5
WestHatch50 views
discussion post.pdfdiscussion post.pdf
discussion post.pdf
jessemercerail70 views
Psychology KS4Psychology KS4
Psychology KS4
WestHatch52 views
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865467 views
Streaming Quiz 2023.pdfStreaming Quiz 2023.pdf
Streaming Quiz 2023.pdf
Quiz Club NITW87 views
ICANNICANN
ICANN
RajaulKarim2057 views
Chemistry of sex hormones.pptxChemistry of sex hormones.pptx
Chemistry of sex hormones.pptx
RAJ K. MAURYA97 views
Plastic waste.pdfPlastic waste.pdf
Plastic waste.pdf
alqaseedae81 views
ICS3211_lecture 08_2023.pdfICS3211_lecture 08_2023.pdf
ICS3211_lecture 08_2023.pdf
Vanessa Camilleri68 views
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com100 views
STERILITY TEST.pptxSTERILITY TEST.pptx
STERILITY TEST.pptx
Anupkumar Sharma102 views
Azure DevOps Pipeline setup for Mule APIs #36Azure DevOps Pipeline setup for Mule APIs #36
Azure DevOps Pipeline setup for Mule APIs #36
MysoreMuleSoftMeetup75 views
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1449 views
GSoC 2024GSoC 2024
GSoC 2024
DeveloperStudentClub1049 views
Psychology KS5Psychology KS5
Psychology KS5
WestHatch53 views
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA156 views

This should be solved in the matrix.cpp file. Write a program which .docx

  • 1. This should be solved in the matrix.cpp file. Write a program which multiplies two matrices. The matrices may be any size, contain integers, and will come as input from the user. Each matrix will be input with the columns separated by spaces and the rows each on a new line. The end of each matrix will be specified by an empty line with no integers. Your program should print the resulting matrix with each column separated by a space, and each row on a new line. Remember that the matrix product is defined as: (AB)_jf = sum of (A_ik * B_kj) for k = 1 to m (where m is the number of columns in A) Your program should output an error if the dimensions of the input matrices are incompatible (the number of columns in the first is not equal to the number of rows in the second). Each input matrix should be stored in a multidimensional integer array. You may also want to use a multidimensional array to store the result matrix. All three matrices have sizes less or equal 10 by 10. The program should print a string of text to the terminal before getting input from the user. A session should look like one of the following examples (including whitespace and formatting), with a possibly matrix in the output: Enter first matrix: 1 2 3 m Enter second matrix: 7 8 9 0 1 2 The product is: 28 14 79 44 Enter first matrix: 12 3 Enter second matrix: 4 5 6 The two matrices have incompatible dimensions. Each string printed by the program should include a newline at the end. but no other trailing whitespace. Solution int main(){
  • 2. int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p; printf(" Enter the row and column of first matrix"); scanf("%d %d",&m,&n); printf(" Enter the row and column of second matrix"); scanf("%d %d",&o,&p); if(n!=o){ printf("Matrix mutiplication is not possible"); printf(" Column of first matrix must be same as row of second matrix"); } else{ printf(" Enter the First matrix->"); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf(" Enter the Second matrix->"); for(i=0;i<o;i++) for(j=0;j<p;j++) scanf("%d",&b[i][j]); printf(" The First matrix is "); for(i=0;i<m;i++){ printf(" "); for(j=0;j<n;j++){ printf("%dt",a[i][j]); }
  • 3. } printf(" The Second matrix is "); for(i=0;i<o;i++){ printf(" "); for(j=0;j<p;j++){ printf("%dt",b[i][j]); } } for(i=0;i<m;i++) for(j=0;j<p;j++) c[i][j]=0; for(i=0;i<m;i++){ //row of first matrix for(j=0;j<p;j++){ //column of second matrix sum=0; for(k=0;k<n;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; } } } printf(" The multiplication of two matrix is "); for(i=0;i<m;i++){ printf(" "); for(j=0;j<p;j++){ printf("%dt",c[i][j]);