Determine the number of natural numbers, considering them in ascending order
September 2, 2021 | education
| Determine the number of natural numbers, considering them in ascending order, the sum of cubes of which does not exceed 50,000. Language Pascal
In the while loop, for a certain n, the sum is exceeded. The last value of n, at which there was no excess yet, should be less by one. That is why not n is printed, but n – 1.
var n, s: integer;
begin
n: = 0;
s: = 0;
while s <50000 do
begin
n: = n + 1;
s: = s + n * n * n
end;
writeln (‘The sum of the first cubes’, n-1: 3, ‘natural numbers does not exceed 50,000 and is equal to’, s-n * n * n, ‘.’);
writeln (‘Adding another number cube (‘, n, ‘^ 3 =’, n * n * n, ‘) increases the sum to’, s, ‘.’)
end.
One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.