answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int a[4][4],b[4][4],c[4][4],i,j;

printf("enter the elements of matrix a");

for(i=0;i<=3;i++)

for(j=0;j<=3;j++)

scanf("%d",&a[i][j]);

printf("the first matrix is");

for(i=0;i<=3;i++)

{

printf("\n");

for(j=0;j<=3;j++)

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

}

printf("Enter the elements of second matrix");

for(i=0;i<=3;i++)

for(j=0;j<=3;j++)

scanf("%d",&b[i][j]);

printf("the second matrix is");

for(i=0;i<=3;i++)

{

printf("\n");

for(j=0;j<=3;j++)

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

}

for(i=0;i<=4;i++)

for(j=0;j<=4;j++)

c[i][j]=a[i][j] + b[i][j];

printf("the addition of matrix is");

for(i=0;i<=3;i++)

{

for(j=0;j<=3;j++)

printf("%d\t",c[i][j]);

printf("\n");

}

getch();

} Answer by sujit saxena:

#include<stdio.h>

#include<conio.h>

void main()

{

int a[20][20],b[20][20],c[20][20],i,j,r1,r2,c1,c2,ta,tb;

clrscr();

printf("Enter order of Matrix A: ");

scanf("d",&r1,&c1);

ta=r1*c1;

printf("\nEnter %d elements=",ta);

for(i=0;i<r1;i++)

{

for(j=0;j<c1;j++)

scanf("%d",&a[i][j]);

}

printf("\nEnter order of Matrix B: ");

scanf("d",&r2,&c2);

tb=r2*c2;

if(r1==r2 && c1==c2)

{

printf("\nEnter %d elements=",tb);

for(i=0;i<r2;i++)

{

for(j=0;j<c2;j++)

scanf("%d",&b[i][j]);

}

for(i=0;i<r1;i++)

{

for(j=0;j<c2;j++)

c[i][j]=a[i][j]+b[i][j];

}

printf("\nSum of matrix is\n");

for(i=0;i<r1;i++)

{

for(j=0;j<c2;j++)

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

}

else

printf("\nAdddition is not possible pls enter same matrices");

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int a[2][2],b[2][2],m,n,i,j,c[8][8],p,q,k,h;

clrscr();

printf("Enter the size of matrix1\n");

scanf("d",&m,&n);

printf("Enter the matrix1\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&a[i][j]);

}

}

printf("Enter the size of matrix2\n");

scanf("d",&p,&q);

printf("Enter the matrix2\n");

for(i=0;i<p;i++)

{

for(j=0;j<q;j++)

{

scanf("%d",&b[i][j]);

}

}

for(i=0;i<k;i++)

{

for(j=0;j<h;j++)

{

c[i][j]=a[i][j]+b[i][j];

}

}

printf("Added matrix is");

for(i=0;i<k;i++)

{

for(j=0;j<h;j++)

{

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

}

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

int main()

{

const int M=3, N=3;

int c[M][N], d[M][N],e[M][N];

int i,j;

printf("nEnter the elements of martices c and d row-wise");

printf("nIn the format c[i][j], d[i][j]...n");

for(i=0; i<M; i++)

for(j=0; i<N; j++)

scanf("%d,%d",&c[i][j],&[i][j]);

printf("nThe matrix c as entered is ... n");

print_matrix (c);

printf("nThe matrix d as entered is...n");

print_matrix(d);

for(i=o;i<M;i++)

for(j=0;j<N;j++)

e[i][j] = c[i][j] + d[i][j];

printf("nThe matrix e as a sum of c and d is ... n");

print_matrix(e);

return 0;

}

print_matrix(int x[][])

{

int i,j;

for(i=0;i<m;i++){

for(j=o;j<N;j++)

print("%4d", x[i][j]);

printf("n");

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<conio.h>

#include<process.h>

void read_matrix(int x[10][10],int r,int c)

{

int i,j;

for(i=0;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&x[i][j]);

}

void print_matrix(int x[10][10],int r,int c)

{

int i,j;

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

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

printf("\n");

}

}

void add_matrix(int x[10][10],int y[10][10],int z[10][10],int r,int c)

{

int i,j;

for(i=0;i<r;i++)

for(j=0;j<c;j++)

z[i][j]=x[i][j]+y[i][j];

}

void main()

{

int a[10][10],b[10][10],c[10][10],ra,ca,rb,cb;

clrscr();

printf("Enter order of 2 matrices");

scanf("dd",&ra,&ca,&rb,&cb);

if(ra!=rbca!=cb)

{

printf("addition is not possible");

exit(0);

}

printf("Enter A\n");

printf("Enter B\n");

read_matrix(a,ra,ca);

read_matrix(b,rb,cb);

add_matrix(a,b,c,ra,ca);

print_matrix(c,ra,ca);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Write a program to add two matrices using the concept of arrays.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to add two matrices using functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program in C using the fprint and fscan functions?

By using those two functions in your code.


How do you develop a JAVA program that computes matrices?

Matrices can't be "computed" as such; only operations like multiplication, transpose, addition, subtraction, etc., can be done. What can be computed are determinants. If you want to write a program that does operations such as these on matrices, I suggest using a two-dimensional array to store the values in the matrices, and use for-loops to iterate through the values.


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


Write C program using functions to simulate a Calculator with the basic functions - square root and reciprocal?

trytytytytytytytytrf 6 bcvvtgujhy6


Why we write java program using classes?

Classes are well organised functions in java which help discriminate between two different functions.


What is the importance of functions in a c plus plus program?

Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.


How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


Write a c program using dynamic memory allocation function calloc to find sum of two matrices and also print the resultant matrix?

printf("%s",per&gt;50?:"pass",per&lt;50?:"fail");


What is the importance of using functions in a c program?

C programs do not function without functions.


Write a sample program using ASPNET explaining all the syntax and semantics of the program?

write a sample program using asp.net explaining all the syntax and semantics of the program


How can you use a sentence using matrices?

Which one of those matrices is more comfortable to sleep on?


Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling