₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,741 members, 8,513,474 topics. Date: Thursday, 05 November 2026 at 05:40 AM

Toggle theme

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

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

1 Reply (Go Down)

Help Out With Algorithm To Add Multiple Numbers by Seconsol92(op): 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(op): 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
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

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

What Could Be Wrong With This Php Code? • Paas Innovation: Inovation And The Need For A ‘fail Fast’ Mentality • A Professional Web/mobile App Developer/programmer Needed!