473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Highest and lowest values in a two dimension array.

2 New Member
What code do I use to find the lowest and the highest value in a two dimension array. I have written the code to have a user enter values into the array, as well as getting a total and average of all values in the array. This is the last part of an assignment due on 04/22/2010.

Thank you!
Apr 21 '10 #1
5 5200
jkmyoung
2,057 Recognized Expert Top Contributor
The principles are the same as a one dimensional array:
Go through every element.
If it's the lowest so far, set it to be the current lowest
If it's the highest so far, set it to be the current highest
add the element to your total

To find the average, average = total / number of elements.
Apr 21 '10 #2
geolinc
2 New Member
@jkmyoung
Thank you for reply. How do I set up the lowest = array(0) in a one dimension to lowest = ? in two dimension array. How do I then set up the nested loops?

Thank you!
Apr 22 '10 #3
whodgson
542 Contributor
Usually a 2 dim array is traversed using 2 loops. Think of a 2 dimension array
as made up of a number of rows of columns. The first loop specifies the row and the second (nested) loop specifies the column. Array{5][6] could be thought of as an array holding 5 rows, each row comprising 6 columns. In such an array the seventh element would reside at array[i][j] where i=1(2nd row) and j=1(2nd col) because the first element`s array address is array[0][0]
Apr 22 '10 #4
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Initially lowest and highest value point to [0][0]th index. Something like this
Expand|Select|Wrap|Line Numbers
  1. int lowest = array[0][0];
  2. int highest = array[0][0];
  3.  
After this traverse through 2 loops(basically one for each dimension). And compare the value with lowest and highest. And change the value of highest and lowest accordingly.

Regards
Dheeraj Joshi
Apr 22 '10 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
Highest and loweset element of a 2D array is not a single int.

This code:

Expand|Select|Wrap|Line Numbers
  1. int array[3][4];
would require that your find the lowest array of 4 int elements in the 2D array of 3 elements.

If you are only interested in the lowest single int, then treat this array as an 1D array of 12 ints. You don't need double loops, etc.
Apr 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7971
by: Wonder | last post by:
For compiler g++ on Linux, it doesn't work if I use int **data = new int; Can I new an array of int* first, and new an one-dimension array for the first int*, then use a loop to make every...
4
1902
by: Michael Kirchner | last post by:
Hi everybody The output of my multiple dimension array is quite confusing. Im declaring an array, store some values in it and then I save the array in a session variable. On an other page I...
9
7737
by: James | last post by:
Hi, I am new to C++. I want to directly create a dynamic two-dimension double array, i.e. double pp. I found the "new" is only for one-dimension array, i.e. double *p = new p. How to "new" a...
21
13449
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
4
4319
by: Bill Sun | last post by:
Hi, All I have a conventional question, How to create a 3 dimension array by C language. I see some declare like this: int *** array; int value; array = create3Darray(m,n,l);
3
4540
by: tg | last post by:
How can I sort a two-dimension array on the first dimension in the array? If there's not a way to do it, how can I return the values of the first dimension so that I can sort the values myself...
7
3331
by: Jan | last post by:
Hi there, Is there a fast way to get the highest value from an array? I've got the array strStorage(intCounter) I tried something but it all and's to nothing If someone good helpme, TIA
3
16085
by: lostncland | last post by:
I am working on this program. The array has 10 scores. (there is more to this program.) Does the last "for" section make sense? /*Defines a global constant called N throughout the file. ...
1
1661
by: Kris tarun | last post by:
I have a table of a retail store which has almost 13000 customers. and i want to write a query for this.. Group products based on their sales patterns. Highest, lowest, and median values. Use...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.