Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
- * File Name : matrix.c
- * Purpose :
- * Creation Date : 10-02-2012
- * Last Modified : Tue 14 Feb 2012 04:24:56 PM PST
- * Created By : Chance Zibolski
- _._._._._._._._._._._._._._._._._._._._._.*/
- #include <stdio.h>
- #include <stdlib.h>
- /*
- * Write a program which uses arrays to perform matrix multiplication. Assume
- * the matrices are square, and for extra credit, let the user pass in the size
- * on the command line.
- */
- #define COLUMNSIZE 2
- #define ROWSIZE 2
- void matrix_mult(int row_size, int col_size, int **array_1, int **array_2, int **product_array){
- for (int x = 0; x < row_size; ++x) {
- for (int x = 0; x < row_size; ++x) {
- product_array[x][y] = 0;
- }
- }
- for (int col = 0; col < col_size-1; ++col) {
- for (int row = 0; row < row_size-1; ++row) {
- product_array[row][col] = array_1[row][col] * array_2[col][row];
- }
- }
- return;
- }
- void hw2_5() {
- int array_a[][] = { {1, 2},
- {3, 4} };
- int array_b[][] = { {5, 6},
- {7, 8} };
- int **product_array = (int*)malloc(sizeof(int) * COLUMNSIZE * ROWSIZE);
- matrix_mult(ROWSIZE, COLUMNSIZE, array_a, array_b, &product_array);
- return;
- }
- int main (int argc, char **arv) {
- hw2_5();
- return 0;
- }
Add Comment
Please, Sign In to add comment