import random
N = [random.randint(0, 100) for i in range(10)]
print ("Array is:", N)
sum_less_50 = 0
Count_less_50 = 0
sum_more_50 = 0
Count_more_50 = 0
for elem in N:
if elem >= 50:
Count_more_50 += 1
sum_more_50 += elem
else:
Count_less_50 += 1
sum_less_50 += elem
print("Awerage of nums, that < 50: ", end = "")
if Count_less_50 > 0:
print(sum_less_50 / Count_less_50)
else:
print(0)
print("Awerage of nums, that >= 50: ", end= "")
if Count_more_50 > 0:
print(sum_more_50 / Count_more_50)
else:
print(0)
program raf105;
var
white,blue,red,x,y,z: integer;
w,b,r: boolean;
begin
writeln('Ввод:');
readln(white, blue, red, x, y, z);
repeat
w:= false;
b:= false;
r:= false;
if white >= x
then begin
white-= x;
blue+= 1;
end
else w:= true;
if blue >= y
then begin
blue-= y;
red+= 1;
end
else b:= true;
if red >= z
then begin
red-= z;
white+= 1;
end
else r:= true;
until w and b and r;
writeln('Вывод:');
writeln(white,' ', blue,' ', red);
end.
PascalABC 3.4.2
Каждый следующий член с знаменателем n! получается умножением предыдущего на
. Очевидно, последовательность убывает по модулю, так что достаточно пройтись циклом, и, если новый вычисленный член по модулю меньше 0,0001, остановиться.
Окажется, что уже пятый член меньше ε, так что выведется только 4 числа.
Код:
#include <iostream>
#include <cmath>
int main() {
const double x = 0.5;
const double eps = 0.0001;
double term = x * x / 2;
for (int n = 3; std::abs(term) > eps; n++) {
std::cout << term << " ";
term *= -x/n;
}
}
Вывод:
0.125 -0.0208333 0.00260417 -0.000260417