Thread: Matrix multiplication using pointers

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    4

    Matrix multiplication using pointers

    Code:
    #include<stdio.h>
    Code:
    #include<conio.h>
    void main()
    {
        int *a[2][2],*b[2][2],*c[2][2],i,j,k;
        Printf("\n ENTER a MATRIX ELEMENTS\n");
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                scanf("%d",&*(*(a+i)+j));
            }
        }
        printf("\n ENTER b MATRIX ELEMENTS\n");
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                scanf("%d",&*(*(b+i)+j));
            }
        }
        printf("\n MATRIX MULTIPLICATION\n");
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                for(k=0;k<2;k++)
                { 
                   (*(*(c+i)+j))+=(*(*(a+i)+k))*(*(*(b+k)+j));
                }
                printf("%d-",(*(*(c+i)+j)));
            }
        }
    getch();
    }
    

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    it's good to see you know how to paste code.while you figure out how to ask questions,you could read this

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    4
    On running this program, i am getting an error of " invalid operands to binary * (have 'int *' and 'int *')" at line 29.
    can anyone suggest a solution to fix this error??

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Why don't you start with
    Code:
        int a[2][2],b[2][2],c[2][2],i,j,k;
    Because what you have at the moment is pure junk.

    Then try and write it using array notation, like
    Code:
    scanf("%d", &a[i][j] );
    If you then want to write it as
    Code:
    scanf("%d", (*(a+i)+j) );
    then good for you, but it doesn't buy you anything. Nobody in the real world uses pointer notation for accessing an array declared using array notation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I note that the OP didn't seem to take advice, or even change their code, from their previous post: Matrix multiplication using pointers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matrix multiplication using pointers
    By NARENDRA.B in forum C++ Programming
    Replies: 4
    Last Post: 02-17-2014, 11:03 AM
  2. Problem with 'Matrix Multiplication using Pointers'
    By JennyG in forum C Programming
    Replies: 20
    Last Post: 07-30-2012, 12:58 PM
  3. Replies: 6
    Last Post: 05-14-2011, 09:28 AM
  4. Hi, problem with pointers and matrix multiplication
    By Phadelity in forum C Programming
    Replies: 2
    Last Post: 11-23-2010, 11:53 PM
  5. Matrix Multiplication
    By davidvoyage200 in forum C++ Programming
    Replies: 4
    Last Post: 11-20-2002, 04:24 PM