Design a program to add all numbers in an array

Design a program to add all numbers in an array

Page 1 of 1

1 Replies - 3185 Views - Last Post: 25 March 2008 - 02:53 PM Rate Topic: -----

#1 sheed10  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-March 08

Design a program to add all numbers in an array

Post icon  Posted 25 March 2008 - 01:57 PM

how do i Design a program to add all numbers in an array
Is This A Good Question/Topic? 0
  • +

Replies To: Design a program to add all numbers in an array

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,179
  • Joined: 18-April 07

Re: Design a program to add all numbers in an array

Posted 25 March 2008 - 02:53 PM

Create a variable to act as an "accumulator" that is, the value you add to each time so that at the end it will represent the sum. Be sure to start it at zero. Loop through the array from 0 to the size of the array - 1, each time through the loop pull the value out of the array and add it to the accumulator variable.

At the end of the loop, your accumulator variable will then have the sum of all values in the array.

So what you will need is a variable to hold the sum, a loop to loop through the array, an array to hold all your numbers and then a print statement to print out the results.

Once you get started and present some code, if you get stuck then you can show your code, any error messages you are getting and what is exactly wrong and then we can help you further.

Hope that makes some sense. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1