Getting the sum of the elements in an array

Hello all,
Any ideas on how to easily get the sum of the elements of an array of floating points (or any data type for that matter ) this is to be part of a method.
arrayName (float [] floaters)
Thanks

int total=0;
for(int a=0; a<array.length; a++){
  total=total+array[a];
}now is that so hard?
or even as a method
public int addUp(int[] array){
   int total=0;
   for(int a=0; a<array.length; a++){
      total=total+array[a];
   return total;
}to be used as
int total=addUp(array);just write your own!

Similar Messages

  • Get every 10 sec a int.value and need to take the sum of the last 18 values

    Hi,
    i get every 10 sec a int.value and need to take the sum of the last 18 values (3 minutes).
    the programm should work permanently.
    I tried with a 1d-array but didn´t get a result. Could anyone help me?
    Best regards
    kasche

    Use the example in the posted link, then add another shift register for your sum of all elements. Dont add all the elements every time, add them to a running total when they come in. You will need to evaluate how big this number is going to get, however, and decide if you should use an I64 for your running total of all elements. Even this will overflow eventually. 
    So your code would look like that posted by GerdW in the above link, then add a shift register with a starting value of 0. Then add your input value to the value comming from this shift register and send the output to the shift register's output terminal. This creates your running total of all values. The code by GerdW provides your "last 18 elements" total in a very efficient manner, just change the 15 to an 18.
    I have attached a sample bit of code to make it clear. I saved it in LV 8.0 so more people can open it.
    CyberTazer
    Software Systems Engineer
    Attachments:
    Running 18 total.vi ‏11 KB

  • How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    On the iPad my example looks like this:
    To fill the formula down you tap cell and then Fill:
    And drag the bottom part of the yellow rectangle down:
    Wayne's example would look similar.
    SG

  • The cumulative balance displayed in FS10N does not match the sum of the det

    Hello,
    The cumulative balance displayed in FS10N does not match the sum of the details.  For example, we have a GL disbursement account that has a ***. Balance of 8 million.  The debit is 2 million and the credit is 10 million. But, when you drill down on the ***. Bal. for the current period, the sum of the details is 9 million.  According to our users, the 2 balances should equal.  I did a search in this forum and found 1 post stating they had the same issue and the answer was to run f.16. Has anyone experienced this and if so, how did you handle it?  I'm not sure how f.16 functions.  Do we have to run it for each consecutive year?  I'm not a FI specialist.  I'm responsible for data archiving and the users think it's related to archiving.  However, we have a test system that was resynced with production prior to when archiving was done and it shows that this issue is pre-existing.
    Thank you very much in advance,
    Lourdes

    Hello,
    There is a possibility that you have activate line item display for some of the accounts at a later stage. Meaning that earlier postings were not be shown for the earlier postings but only totals will be made available. Therefore, obviously there is bound to be difference between line item report and totals report.
    You need to identify which accounts are being changed with line item display at a later stage.
    In case if you forget to keep GL Line item display for an account, but the posting are already made the following steps you would required to get the line item display retrospectively.
    1. Note that you are NOT required to make the balance of that GL account to ZERO. Please do not confuse with Open Item Management.
    2. Put the check box line item display for the account in FS00. Make sure you are entering right company code.
    3. Block the account for posting in COA Segment and Company Code Segment in FS00
    4. Go to SA38 and run program RFSEPA01 (Give correct GL Account and Company Code)
    5. Now, remove the block you kept on the GL Account in FS00.
    This will reset the line item display retrospectively.
    Hope this will solve your problem.
    Regards,
    Ravi

  • Total Baseline Hours For A Resource Does Not Equal the Sum of the Weekly Baseline Hours for that Resource

    Hi,
    I am using Project Server 2010. I have a project schedule that has been baselined and no actual work has been charged to it. The project has 3 resources. I am in the Resource Usage View. With 2 of the three resources, the hours in the Baseline Work Column
    on the left side of the view do not equal the sum total of weekly hours in the Timephased Grid. For instance, for resource JB the Baseline Work hours column says 1,392. When I total his weekly hours in the timephased grid I get 1368 hours; a variance
    of 24. Resource RS has 794.5 hours in the Baseline Work column but the sum total of his weekly timephased grid hours is 710.5, a variance of 84 hours. In both cases, the sum of the hours in the timephased grid is less than the hours in the Baseline Work column.
    What would be causing this? (I am cutting and pasting the weekly hours in the timephased grid into Excel and using the Excel sum function total).  Is there a better timephased view I should be looking at to try to find the "missing
    hours"? I have seen this before in project and it really has me stumped. Thanks.
    Judy Washington

    Hi Judy,
    I could not reproduce your issue. Is your Project Server patched with the latest SP and CU?
    Also can you reproduce this unexpected behavior with another project?
    Can you split your screen from the resource usage view, display the resource form and click right on the grey part selecting "schedule"? Then you'll have the scheduled start and finish dates for the resource's assignments. This is to be sure that
    you are not missing any parts of the assignments due to a wrong zoom in the timephased grid.
    Hope this helps,
    Guillaume Rouyre, MBA, MCP, MCTS |

  • The sum of the confirmed quantity exceeds the sum of stock items

    Hi,
    I have two sales order. Material is same. Both of them related project stok.
    First sales order's qty=1. I created purchase order and post goods receipt.
    Second sales order's qty=2. I created only purchase order.
    I cannot create delivery for first sales order. System giving message.
    Information message : The sum of the confirmed quantity exceeds the sum
    of stock items
    20000978     10     Only 0 ST of material 7ML18301CF  available
    20000978     10     An item with no delivery quantity is not permitted. Item will be deleted.
    But I have a 1 qty on project stock.
    Please help me.

    hi,
    this is to inform you that,
    please run this report in SE38, SDRQCR21 if you have any inconsistencies in the system.
    it seems there is an issue with MARD-DISKZ  & please correct it.
    but i have a doubt MB51 is material document llist.  why you are checking stock there.
    please confirm.
    regards,
    baljia
    Edited by: balaji timmampalli achari on Nov 17, 2010 9:00 AM

  • How to change the properties of individulal elements in an array?

    Hi all,
    I have an array (size is 25) of string and I want to disable and grayout half of them. But how do I do it? How do I change the properties of individual elements in an array? I have tried to use some of the examples given in the discussion forums, but it didint work for the task mentioned above. Anybody would be able to help me with a suitable example that can be specifically used for disable or enable the individual array  elements?
    Dev

    Telemaque wrote:
    The user will see the first half of the string elements filled-in and the lower half grayed-out (to be filled in later).  Make a test VI, play around.
    ... except that all elements "greyed out" with this method contain the default string for the array element (blank by default, but changeable). There is no way to have meaningful, unique text in the greyed out elements.
    I would suggest to use a listbox as control/indicator. Here elements can easily be disabled programmatically.
    LabVIEW Champion . Do more with less code and in less time .

  • Display the Sum in the break header

    Is it possible to display the Sum in the break header instead of the breaker footer? Thanks.

    You can put a sum calculation anywhere you want. Insert a cell, and copy (or move) the existing sum formula into your newly created cell(s). If you stay within the block (table) then the numbers will stay the same. If you move outside the block (into a stand-alone cell, for example) then you may have to set the context of the calculation.
    Note that a running total may return different results than a standard total, which makes sense.

  • My hard drive is clogging up automatically. The personal folder is now 921 GB which is much larger than the sum of the subfolders. I cannot see what's causing this or prevent this from happening. Anyone?

    My hard drive on my Imac keeps clogging up automatically. The personal folder is now 925 GB which is much larger than the sum of the underlying subfolders. I cannot see what"s causing this. Anyone?

    You may try one of these utilities to spotlight exactly where the hard drive usage has gone crazy.
          DaisyDisk- http://itunes.apple.com/us/app/daisydisk/id411643860?mt=12
         DiskFalcon   - http://itunes.apple.com/us/app/disk-falcon/id421781596?mt=12
    Items to check manually:
         Duplicate iTune libraries, or music files that are in itune folder AND loose on the harddrive
         Download folder that hasn't been emptied
         Backup software location

  • Divide a column by the Sum of the Column

    Hi!
    I have a challenge in dividing a column by the total of that same column. What I wan to archive is first check if a column is zero before dividing by the total of the column  and then multiply by 100 to get the percentage of total contribution.
    Below is a sample image. I equally will want to round up to 2 decimal places. As it below, the percentage contribution column is derived from the CountOfProduct column
    Thanks so much for the help
    Zionlite

    Use the SUM() OVER() window function, e.g.:
    DECLARE @tablename TABLE
    product VARCHAR(30) ,
    category INT ,
    prodcnt INT
    INSERT INTO @tablename
    VALUES ( 'PROD1', 1, 11 ),
    ( 'PROD2', 1, 10 ),
    ( 'PROD3', 2, 13 ),
    ( 'PROD4', 2, 40 ),
    ( 'PROD5', 3, 1 );
    SELECT O.product ,
    O.category ,
    O.prodcnt ,
    1.0 * O.prodcnt / ( SELECT SUM(I.prodcnt)
    FROM @tablename I
    FROM @tablename O;
    SELECT O.product ,
    O.category ,
    O.prodcnt ,
    1.0 * O.prodcnt / SUM(O.prodcnt) OVER ( )
    FROM @tablename O;
    SELECT O.product ,
    O.category ,
    O.prodcnt ,
    1.0 * O.prodcnt / ( SELECT SUM(I.prodcnt)
    FROM @tablename I
    WHERE O.category = I.category
    FROM @tablename O;
    SELECT O.product ,
    O.category ,
    O.prodcnt ,
    1.0 * O.prodcnt / SUM(O.prodcnt) OVER ( PARTITION BY O.category )
    FROM @tablename O;
    Data by
    Prashanth.
    Caveat: For further processing avoid to formatting of the fraction to percent. Do this in the front-end.

  • How can I calculate the sum of the first two rows in a table?

    I have a table with a repeating row that, when data is merged, always has three rows:
    Support type 1
    1,234,456
    Support type 2
    221,556
    Interest
    11.222
    I have a field where I want to show the sum of Support types 1 and 2.
    I do not want to add the interest to this.
    I'm using FormCalc with the following script on the calculate event of the Total field, which is in the same subform but not in the table:
    data.JP_Page1.subform_Hidden.sub_SupportTotals.NumericField1::calculate - (FormCalc, client)
    $.rawValue = Sum(subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[0].SUBTOTAL,  subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[1].SUBTOTAL)
    I've tried this using both decimal and numeric field types, neither work.
    I feel like I must be hitting a syntax issue, but the code checker isn't exposing it.
    Can anyone help me figure out what is wrong with my script?
    Thanks!
    Janet

    You don't need to do Sum for this, you should use Sum for all rows purpose only..
    $.rawValue = subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[0]. SUBTOTAL +  subform_Hidden.sub_SupportTotals.tbl_SupportSubtotals.DataRow[1].SUBT OTAL

  • Can we change the property of each element of an array using property node or by other methods?

    Hello all,
    Can we change the property of the elements of an array. For example:
    I have an array of combo-boxes. Can i have such a scenario that different combo-boxes of the array will have different items to select an item.
    I am able to set the different "values" in different combo-boxes bu using "to be more specific class" property node.
    But i could not set the different item list in different combo-boxes.
    Please give me the solution.

    Thanks a million dave!!!!!
    I have learnt a very new and innovative thing...
    I just wanna ask you one more question in the above context.
    Can i have listbox or combo-box in a table just like in an excel sheet where we can have listbox by using "data validation" property for different cells having different list.Can i have this in labview. Because for this i have to super-impose the combo-boxes on the table and treat them separately.
    We have to take those combo-box values and put in table and then store it.I have attached one VI to show the scenario.
    And this is the alternative solution of the array problem which u have already given. So please suggest me between the two or any alternative solution.
    Thanks,
    Ankit Madaan
    Attachments:
    Recording _Table.vi ‏19 KB

  • How to calculate the sum of the values of some columns of a table

    hi
    i want to get in the column averages just the average of the values of some columns not all the columns of the table.what i have to change exactly in this block diagram.even if the size of the table is 25,i want the division to be the number of values in each column(= number of rows)
    just like that:
    Solved!
    Go to Solution.
    Attachments:
    operations on some columns.vi ‏10 KB

    i did exactely what u told me, i think i missed something because i don't get the average value of the rows i want
    Attachments:
    average.vi ‏11 KB

  • How to use the AGO function to calculate the sum of the last 12 months?

    year     |     month     |     amount                    
    2009     |     01     |     100                    
    2009     |     02     |     150                    
    2009     |     03     |     120                    
    2009     |     04     |     110                    
    2009     |     05     |     155                    
    2009     |     06     |     180                    
    2009     |     07     |     105                    
    2009     |     08     |     145                    
    2009     |     09     |     200                    
    2009     |     10     |     205                    
    2009     |     11     |     150                    
    2009     |     12     |     120                    
    2010     |     01     |     225
    SUM OF THE LAST 12 MONTHS OF 201001=>225+120+150+205+200+145+105+180+155+110+120+150     *1.865*
    How do I do this? Could anyone help me?
    Thanks.

    hi,
    Create a dummy column in Fx
    Use *Filter ( amount_col using date col= TimeStampAdd(SQLTSI_MONTH, -12 ,date_col)*
    If u want to show at grand total level
    Go with combine with similar request
    same as u mentioned (1st criteria)
    date_col, month, use the above formula (2nd criteria)
    try this and let me know
    Thanks,
    Saichand.v
    Edited by: Saichand Varanasi on Oct 7, 2010 7:27 PM

  • "How would I add the rows of a 640 x 240 2D array together? I mean , the elements of row 1 to the element of row 2 and so on. I want to end up with a 1 d array of 640 elements in which each element is the sum of the other 240 elements in the rows."

    "For explaination , like this
    1 1 1 1 1 1 1 ....... to 640
    +2 2 2 2 2 2 2 .......
    +3 3 3 3 3 3 3 .......
    =6 6 6 6 6 6 6 ....... this is the final 1D array of summed elements."
    Appreciate the sample VI's but I can't open them ( I have Labview 5.01 )

    Here is Mikael solution, expanded to include rows and ready to use as a subVI. Now all is needed is the polymorphic version
    www.vartortech.com
    Attachments:
    Sum_rows_or_colums.vi ‏25 KB

Maybe you are looking for

  • My iphone 4 won't turn on! Help!

    I have an iphone 4, and it doesn't turn on. My charger was having some problems earlier, so I picked up a new one and this one doesn't work on my phone as well. My Hold button broke a few months ago so I've been using assistive touch to turn off my p

  • Aging Policy Problem

    Dear All I am facing problem with the aging policy in iplanet messaging server.My aging policy is not working Please find the below information for your reference 1) bash-2.03# ./imsimta version iPlanet Messaging Server 5.2 Patch 1 (built Aug 19 2002

  • Modify Method in Class

    Hi All, In Txn SE24, we entered CL_OIURV01_RD_DRIVER to modify it. In "Attributes" tab we can edit many attributes but few are disabled and cannot be modified. We need to modify attribute "RD_BOOKINGS" but the Modify Button is disabled. Any suggestio

  • Why we use INTO CORRESPONDING FIELDS OF TABLE

    why we use INTO CORRESPONDING FIELDS OF TABLE

  • Roxio Easy CD Creator

    A few weeks ago I installed Easy CD Creator 6 on my machine to duplicate some data CDs. The machine refused to read any disks inserted, so I uninstalled CD Creator and gave up. Since then i-tunes puts a message on the screen to the effect that driver