Thread: add element of matrix-Urgent

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    39

    add element of matrix-Urgent

    Please , I need some help to add the elements of a matrix.

    my program must read several matrices from a file and add all element for each matrix.

    This is how I did it

    Code:
    for(i=0;i<size;i++)
    {
    for(j=0;j<size;j++)
    sum=sum+A[i][j];
    }
    I initialized sum BEFORE the while loop (which is set to read all matricces unitil the end of file).
    size is the size of the matrix.

    I get wrong results.
    can someone tell me what I am doing wrong?

    thank you
    B

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    After you've read the matrices in, print them out to make sure they look good.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. *operator overloading: scalar matrix multiplication
    By gemini_shooter in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2009, 01:14 PM
  2. Simple operator overloading issue
    By Desolation in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2007, 08:56 PM
  3. Weird errors.
    By Desolation in forum C++ Programming
    Replies: 20
    Last Post: 05-09-2007, 01:10 PM
  4. Replies: 1
    Last Post: 03-06-2006, 07:57 PM
  5. How to add element to the end of a linked list?
    By Yin in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2002, 03:04 PM