Accumulate Multiple Values
From Progzoo
Two Accumulators
You can use more than one accumulator in the same loop.
Contents |
Find the average
Use two accumulators, sum and count. Return the two values in a string.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Odds and evens
Use two accumulators, odd and evens to count the number of odd numbers and the number of even numbers. Return the two numbers in a string separated by a space.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
More odd than even?
Return the word "odd" if the sum of the odd numbers is bigger than the sum of the even numbers. Return the word "even" otherwise.
The list {1,3,5,8,6} returns "even" because 1+3+5 is less than 8+6.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Small, medium, large
- Numbers less than 2 are small.
- Numbers greater than 4 are large.
- Other numbers are medium.
Reurn the number of small, medium and large numbers.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
