Guest User

Untitled

a guest
Jun 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. /* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
  2.  
  3. * File Name : matrix.c
  4.  
  5. * Purpose :
  6.  
  7. * Creation Date : 10-02-2012
  8.  
  9. * Last Modified : Tue 14 Feb 2012 04:24:56 PM PST
  10.  
  11. * Created By : Chance Zibolski
  12.  
  13. _._._._._._._._._._._._._._._._._._._._._.*/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. /*
  19.  * Write a program which uses arrays to perform matrix multiplication. Assume
  20.  * the matrices are square, and for extra credit, let the user pass in the size
  21.  * on the command line.
  22.  */
  23.  
  24. #define COLUMNSIZE 2
  25. #define ROWSIZE 2
  26.  
  27. void matrix_mult(int row_size, int col_size, int **array_1, int **array_2, int **product_array){
  28.  
  29.  
  30.     for (int x = 0; x < row_size; ++x) {
  31.         for (int x = 0; x < row_size; ++x) {
  32.             product_array[x][y] = 0;
  33.         }
  34.     }
  35.  
  36.     for (int col = 0; col < col_size-1; ++col) {
  37.         for (int row = 0; row < row_size-1; ++row) {
  38.             product_array[row][col] = array_1[row][col] * array_2[col][row];
  39.         }
  40.     }
  41.  
  42.  
  43.     return;
  44. }
  45.  
  46. void hw2_5() {
  47.  
  48.     int array_a[][] = { {1, 2},
  49.               {3, 4} };
  50.  
  51.     int array_b[][] = { {5, 6},
  52.               {7, 8} };
  53.  
  54.     int **product_array = (int*)malloc(sizeof(int) * COLUMNSIZE * ROWSIZE);
  55.  
  56.     matrix_mult(ROWSIZE, COLUMNSIZE, array_a, array_b, &product_array);
  57.  
  58.     return;
  59. }
  60.  
  61. int main (int argc, char **arv) {
  62.  
  63.     hw2_5();
  64.  
  65.     return 0;
  66. }
Add Comment
Please, Sign In to add comment