Const N = 4; Var A:array[1..N,1..N] of real; B,X,AX:array[1..N] of real; i,j:integer; S:real; Begin Randomize; Write('B(',N,'):'); For i:= 1 to N do Begin B[i]:=random(721)-360; Write(' ',B[i]:4) End; WriteLn; Write('X(',N,'):'); For i:= 1 to N do Begin X[i]:=random(721)-360; Write(' ',X[i]:4) End; WriteLn; WriteLn('A(',N,',',N,'):'); For i:= 1 to N do Begin Write(' '); For j:= 1 to N do Begin A[i,j]:=random(721)-360; Write(' ',A[i,j]:4) End; WriteLn; End; WriteLn; Write('AX:'); For i:= 1 to N do Begin AX[i]:=0; For j:= 1 to N do Begin AX[i]:=AX[i]+A[i,j]*X[j]; End; Write(' ',AX[i]) End; WriteLn; Write('AX+B:'); For i:= 1 to N do Begin X[i]:=AX[i]+B[i]; Write(' ',X[i]) End; WriteLn; Write('|Ax+b| = '); S:=0; For i:= 1 to N do Begin S:=S+X[i]*X[i]; End; WriteLn(Sqrt(S)) End.
from random import randint
n = 100
arr = [randint(20, 100) for _ in range(n)]
even = len([n for n in arr if n % 2 == 0])
odd = len([n for n in arr if n % 2 != 0])
print(*arr)
print('Even:', even)
print('Odd:', odd)
Пример вывода:
29 54 28 65 20 21 66 78 95 22 87 44 61 92 25 26 57 40 67 22 91 62 38 21 44 30 54 82 54 72 72 54 68 52 21 79 85 59 62 47 62 37 80 59 36 30 87 55 39 100 36 33 66 91 27 76 40 100 47 31 73 72 93 62 38 57 85 87 26 52 34 65 56 51 21 22 65 85 58 87 95 67 70 75 30 68 44 35 85 87 92 98 76 52 85 57 20 68 37 67
Even: 53
Odd: 47
(2)
from random import randint
n = 100
arr = [randint(1000, 2000) for _ in range(n)]
numbers = [int(str(n)[-2]) for n in arr]
count = len([n for n in numbers if n % 2 == 0])
print(*arr)
print('Answer:', count)
Пример вывода:
1689 1009 1036 1513 1801 1652 1382 1004 1172 1258 1876 1410 1439 1597 1364 1720 1672 1704 1571 1887 1716 1952 1180 1818 1528 1385 1976 1088 1939 1238 1519 1121 1505 1422 1713 1651 1723 1330 1537 1139 1907 1561 1866 1345 1009 1400 1999 1207 1431 1704 1604 1434 1062 1830 1897 1753 1735 1247 1673 1683 1628 1446 1758 1598 1326 1627 1987 1085 1695 1324 1543 1680 1237 1013 1476 1145 1258 1991 1163 1963 1103 1589 1616 1418 1823 1668 1250 1738 1413 1690 1947 1719 1727 1528 1910 1903 1239 1065 1403 1258
Answer: 51
N = 4;
Var
A:array[1..N,1..N] of real;
B,X,AX:array[1..N] of real;
i,j:integer;
S:real;
Begin
Randomize;
Write('B(',N,'):');
For i:= 1 to N do
Begin
B[i]:=random(721)-360;
Write(' ',B[i]:4)
End;
WriteLn;
Write('X(',N,'):');
For i:= 1 to N do
Begin
X[i]:=random(721)-360;
Write(' ',X[i]:4)
End;
WriteLn;
WriteLn('A(',N,',',N,'):');
For i:= 1 to N do
Begin
Write(' ');
For j:= 1 to N do
Begin
A[i,j]:=random(721)-360;
Write(' ',A[i,j]:4)
End;
WriteLn;
End;
WriteLn;
Write('AX:');
For i:= 1 to N do
Begin
AX[i]:=0;
For j:= 1 to N do
Begin
AX[i]:=AX[i]+A[i,j]*X[j];
End;
Write(' ',AX[i])
End;
WriteLn;
Write('AX+B:');
For i:= 1 to N do
Begin
X[i]:=AX[i]+B[i];
Write(' ',X[i])
End;
WriteLn;
Write('|Ax+b| = ');
S:=0;
For i:= 1 to N do
Begin
S:=S+X[i]*X[i];
End;
WriteLn(Sqrt(S))
End.
Пример:
B(4): -51 179 276 -273
X(4): -272 -261 -57 304
A(4,4):
-169 -94 245 -346
-351 -176 280 1
-193 -330 219 -54
338 -57 -44 -328
AX: -48647 125752 109727 -174263
AX+B: -48698 125931 110003 -174536
|Ax+b| = 246563.556248688