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


How do you write a program to performs all airthematic operation between two matrixs using array?

To write a program that performs arithmetic operations between two matrices using arrays, first define two 2D arrays to represent the matrices. Then, create functions for each arithmetic operation (addition, subtraction, multiplication, etc.) that iterate through the elements of the matrices, performing the operation element-wise. Ensure to handle cases where the matrices have different dimensions, as this would affect the validity of the operations. Finally, print the result matrix after each operation.


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.


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 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.....


How do you write assembly language program for displaying a character in 8x8 LED matrix using 8088 microprocessor kit?

To write an assembly language program for displaying a character on an 8x8 LED matrix using the 8088 microprocessor kit, you first need to define the bit pattern for the character in the program. Then, set up the appropriate I/O ports for the matrix, ensuring you understand the pin configuration for rows and columns. The program will typically involve initializing the matrix, sending the bit pattern to the corresponding rows and columns, and implementing a loop to continuously refresh the display. Use instructions like OUT to send data to the ports and DELAY for timing control to ensure the display is stable.


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.