Averaging allows to find the general trends, to understand possible costs, proceeding from the previous experience of expenses or to count the budget on a trip. Finding of an arithmetic average of value is necessary in science, business and life. How to calculate required size?

## Instruction

1. For finding of an arithmetic average of value it is necessary to put all components and the received sum to divide a sum component into quantity. This operation can be presented a formula: average value = ((1) + (2) +... + a(n-1) + a(n)) / n where n is number of the last member of the sum one after another (quantity of composed).

2. For finding of average value of the member of an arithmetic progression it is necessary to put the first member of the sequence with the last and to halve the received sum. Record of expression by mathematical symbols: average of value of a progression = ((1) + a(n)) / 2.

3. Formulas were developed for an arithmetic progression by the great German mathematician Gauss. He found a way of calculation of the sum of all progression with a step in the childhood 1 (a number of natural numbers) without separate addition of her members. For this purpose young Karl put the first member of a progression with the last and increased the sum by half number of members of the sequence.

4. The problem of finding of an arithmetic average of value often meets in programming. For its simple decision it is necessary to use a step cycle (with the course in unit called an increment). In the majority of programming languages (С#, Java, Pascal, PHP) this cycle has the name for.

5. To an entrance to a cycle announce variables S (sum) and sred (arithmetic average). Appropriate them zero value (this process is called initialization). You enter a cycle. To the sum of S add all new members of the sequence. The total arithmetic sum is so formed.

6. After a cycle perform operation: sred = S/n. Notice, the type of variable S has to be integer (at integer composed), and sred - material as as a result of division the fractional number can turn out. So you receive an arithmetic average value in programming.