help on my code PLS!!!

This is a discussion on help on my code PLS!!! within the C++ Programming forums, part of the General Programming Boards category; hi everyone, this is my code that i wrote, but i couldnt do wat i want... so can someone please ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    71

    help on my code PLS!!!

    hi everyone,
    this is my code that i wrote, but i couldnt do wat i want... so can someone please let me know .....

    this code is to sum up all the row and column, is that possible making those two part into single statement....
    i mean :
    Code:
    {
    
    //sum column
    
    //sum row
    
    }
    Code:
    //sum each row
    
        for(int row = 0; row < n; row++)
        {
            int sumRow = 0;
            
            for(int col = 0; col < n; col++)
            sumRow = sumRow + matrix[row][col];
            
            cout<<"sum of row "<<row+1<<" = "<<sumRow<<endl;
       
       }   
      
    //sum each column
    
        for(int col = 0; col < n; col++)
        {
            int sumColumn = 0;
            for(int row = 0; row < n; row++)
            sumColumn = sumColumn + matrix[row][col];
            
            cout<<"sum of column "<<col+1<<" = "<<sumColumn<<endl;
        }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,742
    Yes, have two more arrays called say
    int rowTotals[n], colTotals[n];

    Now add each matrix[row][col] to the appropriate totals.

    Don't forget to zero all your totals first

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    some example please...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,742
    No..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 08:23 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 01:48 AM
  3. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  4. code fragment pls help
    By Damo in forum C Programming
    Replies: 2
    Last Post: 04-15-2002, 10:57 AM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM

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