Advertisement

help my code please

Started by February 21, 2003 10:19 AM
-1 comments, last by novice_programer 21 years, 8 months ago
gentleman, I''m trying to write a code in C to multiply two linear matrices. The program would take as input the dimensions of each matrix, as well as the components of each matrix. I''ve assumed the following as my teat Matrix: 1 0 -2 3 0 6 1 5 4 3 8 -2 0 1 I''m not able to move any further to multiply. I''m kind of stuck in the middle, and a lil frustrated. Please provide me some help. and yes this is not Homework or office work. I''m a sophomore student. cheers, #include <stdio.h> #include <stdlib.h> void fill_matrix(first_matrix, n); void print_matrix(first_matrix, n); void fill_matrix(int **first_matrix, int row, int col) { int i, j, num; printf(" Please enter the values for this Matrix : "); for (i=0; i < row; ++i) for (j = 0; j < col; ++j) { scanf("%d", #); first_matrix[j] = num; } } void print_matrix(int **first_matrix, int row, int col) { int i, j; for (i=0; i < row; ++i) { for (j = 0; j < col; ++j) printf("%d", first_matrix[j]); putchar(''\n''); } putchar(''\n''); } int main() { int row, col, **first_matrix; //**second_matrix, n; int i = 0; printf(" Enter the dim. of 1st Matrix in rows & cols:"); scanf("%d",&row); scanf("%d", &col); first_matrix = calloc(row, sizeof(int *)); for(i = 0; i< row; i++) { first_matrix = calloc(col, sizeof(int)); } fill_matrix(first_matrix, row, col); print_matrix(first_matrix, row, col); for(i = 0; i < row; i++) { free(first_matrix); } free(first_matrix); } </i>

This topic is closed to new replies.

Advertisement