Eighteen problems on a list of numbers read one at a time: sums and counts first, then products and powers, the smallest and the largest, and lists that end with a zero. Nothing needs an array — each number is used and forgotten.
long longfor every sum and product: Sum, Sum of numbers divisible by m, Triangular number, Factorial (up to 20!), Powers of the number x and both geometric sums overflow anint.- Odd positions prints the positions, not the numbers: the loop counter, from 1.
- The nearest number to x: keep the best number and its distance
abs(x - a), and replace them only when a new number is strictly closer. - Stop at the zero. In the problems that end with 0, some tests have more numbers after it, and some start with it — then the list is empty.
- Maxima to zero is the lesson's "how many times the maximum occurs": a new maximum restarts the count at 1, an equal one adds to it.
- In the geometric sums, multiply the power before adding it, as in the lesson, and switch the sign each round for the alternating one.