answersLogoWhite

0

Matrix Add

/* Program MAT_ADD.C

**

** Illustrates how to add two 3X3 matrices.

**

** Peter H. Anderson, Feb 21, '97

*/

#include <stdio.h>

void add_matrices(int a[][3], int b[][3], int result[][3]);

void print_matrix(int a[][3]);

void main(void)

{

int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };

int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };

int r[3][3];

add_matrices(p, q, r);

printf("\nMatrix 1:\n");

print_matrix(p);

printf("\nMatrix 2:\n");

print_matrix(q);

printf("\nResult:\n");

print_matrix(r);

}

void add_matrices(int a[][3], int b[][3], int result[][3])

{

int i, j;

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

{

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

{

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

}

}

}

void print_matrix(int a[][3])

{

int i, j;

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

{

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

{

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

}

printf("\n");

}

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/


Write a program to read your name and reverse it using arrays?

abdulrahman


Write a c program for matrix addition using function?

#include&lt;


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

i cant write


How do you check orthogonality of a matrix using arrays?

the transpose of null space of A is equal to orthogonal complement of A


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.


How do you write a C program to find the adjoint of a matrix?

To write a C program to find the adjoint of a matrix, first, you need to create a function to calculate the cofactor of each element in the matrix. Then, construct the adjoint by transposing the cofactor matrix. The program should read the matrix size and elements from user input, compute the cofactors using nested loops, and finally display the adjoint matrix by transposing the cofactor matrix. Make sure to handle memory allocation for dynamic matrices if needed.


How can you do the same thing as the program below but using strings and arrays in C language?

Program below?!


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


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


C program for matrix multiplication using dynamic memory alllocation?

Poor boy


Are arrays in C created on the stack or the heap?

That depends on where you define them. Arrays defined inside functions are declared on the stack (like other variables defined in functions). Arrays defined outside of any function, or using the static keyword inside a function are allocated in the static data area of the program. Other arrays may be allocated using malloc() (or "new" in C++); these are allocated on the heap.