array add total rows and total colms

This is a discussion on array add total rows and total colms within the C Programming forums, part of the General Programming Boards category; Code: i am trying to display the information in the array as a table and add the total rows and ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    array add total rows and total colms

    Code:
    i am trying to display the information in the array as a table and add the total rows and the total colums separately, can someone help.
    
    #include<stdio.h>
    int main(void)
    {
            int row, col;
            double sum_rows, sum_cols;
            int x[4][5]={{100,120,210,50,15},{120,40,30,50,50},{50,100,100,120,80},{30,250,75,45,20}};
            printf("%25s%17s\n", "Rows #", "Sum of rows");
            for(row=0; row<4; row++){
                    sum_rows = 0;
                    for(col=0; col<5; col++){
                            sum_rows += x[row][col];
            }
            printf("Salesperson %12d%17g\n", row, sum_rows);
            }
            printf("%25s%17s\n", "Colums #", "Sum of colums");
            for(col=0; col<5; col++){
                    sum_cols=0;
                    for(row=0; row<4; row++){
                            sum_cols+= x[row][col];
            }
            printf("Product%17d%17g\n", col, sum_cols);
            }
            return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,753
    i am trying to display the information in the array as a table and add the total rows and the total colums separately, can someone help.
    What do you need help with? Please ask specific questions.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2013, 08:37 AM
  2. sort array of 3 keys while minimizing the total cost
    By nik2 in forum C++ Programming
    Replies: 6
    Last Post: 07-16-2010, 02:10 PM
  3. adding up array column total
    By dmckay in forum C Programming
    Replies: 1
    Last Post: 01-25-2010, 02:14 PM
  4. average of total using array
    By tmoney$ in forum C Programming
    Replies: 2
    Last Post: 05-13-2003, 05:27 PM
  5. total size of dynamic memory allocated array
    By trekker in forum C Programming
    Replies: 10
    Last Post: 03-10-2002, 11:59 AM

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