0% found this document useful (0 votes)
31 views2 pages

Priyan. Matrix

This document contains code to perform addition, subtraction, and multiplication on 2D arrays in C. It first prompts the user to enter the rows and columns of two matrices. It then uses nested for loops to input the elements of each matrix from the user. It checks if the matrices can be multiplied by verifying if the number of columns in the first matrix equals the number of rows in the second. If so, it uses another nested for loop to calculate the product matrix by multiplying the rows of the first with the columns of the second and summing the results. Finally, it prints out the product matrix.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Priyan. Matrix

This document contains code to perform addition, subtraction, and multiplication on 2D arrays in C. It first prompts the user to enter the rows and columns of two matrices. It then uses nested for loops to input the elements of each matrix from the user. It checks if the matrices can be multiplied by verifying if the number of columns in the first matrix equals the number of rows in the second. If so, it uses another nested for loop to calculate the product matrix by multiplying the rows of the first with the columns of the second and summing the results. Finally, it prints out the product matrix.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

2Dimensional Array Addition, Subtraction, Multiplication

void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;

printf("Enter The Rows And Columns And Of The First


Matrix:");
scanf("%d %d",&m,&n);
printf("\nEnter The Rows And Columns And Of The
Second Matrix:");
scanf("%d %d",&p,&q);
printf("\nEnter Elements Of The First Matrix:\n");
for(i=0;i< m;i++)
for(j=0;j< n;j++)
scanf("%d",&a[i][j]);

printf("\nEnter Elements Of The Second Matrix:\n");


for(i=0;i< p;i++)
for(j=0;j< q;j++)
scanf("%d",&b[i][j]);

if(n!=p)
{
printf("Aborting./nMultiplication Of The Above Matrices
Not Possible.");
exit(0);
}

else
for(i=0;i< m;i++)
for(j=0;j< q;j++)
{
c[i][j] = 0;
for(k=0;k< n;k++)
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}

printf("\nThe Product Of The Two Matrices Is:\n\n");


for(i=0;i< m;i++)
{
for(j=0;j< q;j++)
printf(" %d ",c[i][j]);
printf("\n");
}
getch();

2Dimensional Array Addition, Subtraction, MultiplicationBy Shanmugapriyan.

You might also like