473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sum Identical Members of an Array

Hello,

I have a 2-dimensional array:
(not in my actual written code)

alpha[x][y]

I need to sum the 'y' values each time that the 'x' values associated with them are the same. The 'x' values will be doubles with up to 3 decimal places. I then need to output this as another array, preferably in order of size. Is there an easy way to do this?

Thanks in advance for any help.
Feb 3 '08 #1
3 1345
weaknessforcats
9,208 Expert Mod 8TB
I'm sorry, but your problem sounds confusing to me.

Do you mean to compare elements like alpha[2][3] with alpha[2][4] to see of they are equal??

I don't understand what you mean by 'y' values anmd 'x' values.
Feb 3 '08 #2
Sorry if I didn't make it clear. If for an array I have:

alpha[x][y]= {{1, 12},
{2, 6},
{3, 5},
{2, 5},
{1, 15}}

I want to to sum the second number (y), if the numbers in the first array (x) match.

For example from the array above, the number 1 occurs more than once so I want to have a new array with 12+15. I really want to end up with something like this for the above example:

alpha[x][y]={{1, 27},
{2, 11},
{3, 5}}

Although in my program there are more than a million doubles, instead of integers.

I hope this is more clear. The code above is just an example, not what is written in my program.

Thanks
Feb 3 '08 #3
You could sort the array initially using the i values of array[i][j]. Then add the numbers.

Another option could be run 1 loop say 'x' from 0 to length of array-1. Inside this loop run another loop say 'y' from x to length of array. You could check if the values of array[x][0] and array[y][0] are the same and add the values.
Hope this helps.
Feb 4 '08 #4

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

Similar topics

1
by: Phil Powell | last post by:
Consider these two classes. Class Accepter in placement_classes.inc.php works as a form validation object, and it works like a charm: PHP: // placement_classes.inc.php - THIS ONE WORKS! ...
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
8
by: Ares Lagae | last post by:
When adopting the coding style of the standard C++ library, you often run into naming problems because class names are lower case, and member functions do not have get/set prefixes. For example:...
0
by: picander77 | last post by:
Hello! I need to perform the following operation on an XML document: I have a first element containing a list of team (<Teams>). A name is assigned to all teams, as well as a list of their...
9
by: Olumide | last post by:
Thats the question. I know about virtual memory, and the MMU. I just wonder if array members guaranteed to be contiguous in physical memory (and if so, why). Thanks, Olumide
0
by: Adam Warner | last post by:
Hi all, One cannot return a pointer to an array in C since there are no first class array types. But one can return a pointer to an incomplete array via the illegal but widely supported zero...
4
by: Santosh Nayak | last post by:
Hi, Is it possible to sort the array of struct based on the data members. e.g. struct { int a ; float b ; char c ; } TEMP ;
6
by: noone | last post by:
What is the syntax to access members of a structure without explicitly naming the structure in every access? struct mytype { int a; char* b; long c; } IT; How can I access the structure...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.