Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,195,510 members, 7,958,546 topics. Date: Wednesday, 25 September 2024 at 04:53 PM

Help Out With Algorithm To Add Multiple Numbers - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Out With Algorithm To Add Multiple Numbers (834 Views)

Your Toughest Algorithm / Write An Algorithm To Add N Binary Numbers / Help With Algorithm Of Basic Operations Of A Calculator (2) (3) (4)

(1) (Reply) (Go Down)

Help Out With Algorithm To Add Multiple Numbers by Seconsol92(m): 7:56am On Jun 22, 2015
please programmers in the house help me out with algorithm to add multiple numbers (ie 2+3+5+7).
Re: Help Out With Algorithm To Add Multiple Numbers by FincoApps(m): 9:59am On Jun 22, 2015
1. Store each number in an int array
2. Add up the array using a for loop

int[] arr;
int sum = 0;
E.g for(int i=0; i<arr.length; i++)
{
sum = sum + arr[i];
}

But what language are you working with ?
Seconsol92:
please programmers in the house help me out with algorithm to add multiple numbers (ie 2+3+5+7).
Re: Help Out With Algorithm To Add Multiple Numbers by Greatfes17: 2:55pm On Jun 22, 2015
Find a way to store all the numbers. Then use a loop to go through the numbers and add them as it iterates.

In python you can store the numbers in a list or tuple, then use 'for loop' to iterate and add them as you go.

Simpler than anything, pass it as argument to inbuilt sum function.

Happy coding
Re: Help Out With Algorithm To Add Multiple Numbers by Seconsol92(m): 4:59pm On Jun 22, 2015
FincoApps:
1. Store each number in an int array 2. Add up the array using a for loop
int[] arr; int sum = 0; E.g for(int i=0; i<arr.length; i++) { sum = sum + arr[i]; }
But what language are you working with ?
thanks for the help. i am working with java

1 Like

Re: Help Out With Algorithm To Add Multiple Numbers by FincoApps(m): 5:51am On Jun 23, 2015
You welcome smiley
Seconsol92:

thanks for the help. i am working with java
Re: Help Out With Algorithm To Add Multiple Numbers by babatope88(m): 11:47am On Jun 23, 2015
Are the numbers in predictable sequence? If No, then try the suggested method above. But the given example look like a sequence, sum = n/2(2a + (n - 1)d)
Where n is the number of element
d is diff btw first term and 2nd term common difference.
This would be more faster.
Re: Help Out With Algorithm To Add Multiple Numbers by babatope88(m): 11:50am On Jun 23, 2015
Oh!!! not a sequence. Abaachabacha

(1) (Reply)

Fixed Asset Register / {a Passionate Web Developer Need As A Tutor In The Courses Below} / Am In Need Of Mmm Script

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.