multiplication matrix

This is a discussion on multiplication matrix within the C Programming forums, part of the General Programming Boards category; hi everyone..i'm having trouble with multiplication matrix. this is what i came up with so far and i know its ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    17

    multiplication matrix

    hi everyone..i'm having trouble with multiplication matrix. this is what i came up with so far and i know its wrong...nay help would be very appricated....

    void mult_matrix()
    {
    int iArrayFirst[4][4];
    int iArraySecond[4][4];
    int iArrayAnswer[4][4];
    int i;
    int j;

    //get first array from user
    for(i=0;i<4;i++)
    {
    for (j=0;j<4;j++)
    {
    printf("enter value:");
    scanf("%d", &iArrayFirst[i][j]);
    }
    printf("\n");
    }
    //get second array from user
    for(i=0;i<4;i++)
    {
    for (j=0;j<4;j++)
    {
    printf("enter value:");
    scanf("%d", &iArraySecond[i][j]);
    }
    printf("\n");
    }
    //calculate the answer array
    for(i=0;i<4;i++)
    {
    for(j=0;j<4;j++)
    {
    iArrayAnswer[i][j]=iArrayFirst * iArraySecond[i][j];
    }
    }
    print_matrix(iArrayAnswer);

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    11
    I think you have an error in your calculating array algorithm, try this instead:
    Code:
    for(row = 0; row < 4; row++)
    {
    	for(column = 0; column < 4; column++)
    	{
    		iArrayAnswer[row][column] = 0;
    		for(i = 0, j = 0; i < 4 && j < 4; i++, j++)
    			iArrayAnswer[row][column] += (iArrayFirst[row][i] * iArraySecond[j][column]);
    	}
    }
    Lots of edits: Forgot the tags
    Last edited by WanTeD; 05-13-2003 at 03:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 02:30 PM
  2. *operator overloading: scalar matrix multiplication
    By gemini_shooter in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2009, 02:14 PM
  3. Matrix Multiplication ( Accessing data from a file ) HELP
    By six_degreez in forum C Programming
    Replies: 2
    Last Post: 07-24-2008, 06:21 PM
  4. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21