Задача 1. Їдальня закуповує щодня масло та кг по 110 грн. за кілограм, сметану та кг по 35 грн. за кілограм, вершки m3 кг по 70 грн. за кілограм. Визначте суми, потрібні для купівлі окремих продуктів, і загальну суму.
Val(str[i - 1], x, err); if (x mod 2 <> 0) and (x < 0) then begin count += 1; if count = 1 then necheti[1] := x; if count = 2 then necheti[2] := x; if count = 3 then necheti[3] := x;
if count = 3 then begin Writeln('1: ', necheti[1]);
Writeln('2: ', necheti[2]);
Writeln('3: ', necheti[3]); y := true; end;
end;
end;
end;
end.
Объяснение:
Вводить значения строго через пробел и без запятых
program proga;
var str: array of string;
readstr: string; i, x, err, count: integer;
necheti: array [1..3] of integer; y: boolean;
begin
y := false;
while y = false do begin;
Readln(readstr);
str := readstr.Split(' ');
for i := 1 to Length(str) do begin
Val(str[i - 1], x, err); if (x mod 2 <> 0) and (x < 0) then begin count += 1; if count = 1 then necheti[1] := x; if count = 2 then necheti[2] := x; if count = 3 then necheti[3] := x;
if count = 3 then begin Writeln('1: ', necheti[1]);
Writeln('2: ', necheti[2]);
Writeln('3: ', necheti[3]); y := true; end;
end;
end;
end;
end.
Объяснение:
Вводить значения строго через пробел и без запятых
Быстрее всего значение
вычисляется по формуле Виета
Программа на python:
#(c) NaaMan
import math
def fnc1():
a,b = 1, -1
while True:
c = 1 / a
yield c
a = (abs(a) + 2) * b
b = -b
def fnc2():
a, b = 2, 1
while True:
c = a / b
yield c
if a > b:
b += 2
else:
a += 2
def fnc3():
a = 1
while True:
c = 1 / (a * a)
yield c
a += 1
def fnc4():
a = math.sqrt(2)
while True:
c = a / 2
yield c
a = math.sqrt(2 + a)
leibniz = fnc1( )
vallis = fnc2()
squares = fnc3()
viett = fnc4()
n = int( input( 'n = '))
s1 = 0
s2 = 1
s3 = 0
s4 = 1
while n:
s1 += next( leibniz)
s2 *= next( vallis)
s3 += next( squares)
s4 *= next( viett)
n -= 1
print( 'leibniz = ', s1 * 4)
print( 'vallis = ', s2 * 2)
print( 'squares = ', math.sqrt(s3 * 6))
print( 'viett = ', 2 / s4)
Результаты выполнения программы: