Need desperate help with two dimensional array problem

This is a discussion on Need desperate help with two dimensional array problem within the C++ Programming forums, part of the General Programming Boards category; I have ZERO clue how to do/what to do for this program. Can anyone help me out? Write a program ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    7

    Need desperate help with two dimensional array problem

    I have ZERO clue how to do/what to do for this program. Can anyone help me out?
    Write a program that inputs a two-dimensional array (you may use a data
    file, but if you do, have main print out the array) consisting of 5 rows
    and 4 columns of integers, and determines and prints the sum of the
    entries in the row or column of the largest entry.

    The program should have a function that finds the largest element of the
    array and returns the row index and column index of the largest element.
    (The function should do no more, and no less.)

    Be sure not to add the largest element twice in calculating the sum.


    For example: If the array is

    2 1 0 3
    -5 6 8 -10
    0 0 1 2
    5 19 3 15
    -25 6 8 -50

    the function should return 3 for the row index and 1 for the column index
    (as 19 is the largest element of the array). The sum computed and printed
    by main( ) would be the sum of the numbers in row index 3 or column
    index 1: the sum of 5,19, 3, 15,1, 6, 0, 6, namely 55.

    You may not use global variables.
    Use the above example to test your program.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904

    Re: Need desperate help with two dimensional array problem

    or you could just do:

    Code:
    int mat[5] [4]=
    {
    	{ 2, 1, 0, 3},
    	{-5, 6, 8, -10},
    	{0, 0, 1, 2},
    	{5, 19, 3, 15},
    	{-25, 6, 8 -50}
    };
    and then just run through the matrix that way..........

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    I dont understand how we're supposed to "select" the highest number array and add up it's column and row. this lady never taught us any of this $$$$, so if I seem clueless, it's because I am

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    The idea is for you to figure out how to solve that problem, not just recite someone else's solution.

    Think about what you need to accomplish. Not only do you have to go through the array examining one element at a time to find the highest value (think of it as "highest-so-far"), but when you've finished doing that, you have to know exactly where it is in the array (row and column).

    So, set up the appropriate three variables, and try to figure out what to do next.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "this lady never taught us any of this $$$$"

    Did she teach you what a for-loop, a while-loop, and an array are?
    That's all you need to know. If she didn't teach you those things, get a good C++ book, like "Ivor Horton's Beginning C++", for a reference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zero out two dimensional array
    By davo666 in forum C Programming
    Replies: 16
    Last Post: 01-08-2009, 05:28 AM
  2. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 03:56 AM
  3. Problem within multi dimensional array
    By lolguy in forum C Programming
    Replies: 5
    Last Post: 12-26-2008, 08:02 AM
  4. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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