1. , .
2. n.
) n?
) ?
) n.
, (div) (mod) 10.
3. p, (1699 .):
4. :
n (n > 1). , 2, 3 1. 1, () .., 1. : 1 -> 4 -> 2 -> 1. 7: 7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1. 1->4->2->1!
. , .
5. ex e :
, , x x dx e. . , .
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
1. n, 1,2,...,n. : a) max(a1,a2,...,an); ) min(a1, a2,..., n).
: . 4.1.
. 4.1. - 1
Turbo Pascal :
Program max_min_mas;
Var a: Array [1..20] of Real;
n,i: 1..20;
min,max:Real;
Begin
Write(' (_ 1 20)');
ReadLn(n);
WriteLn(' ');
Write('l - ');
ReadLn(a[l]);
max:=a[l]; min:=a[l];
For i:=2 to n do
Begin
Write(i,' - ');
ReadLn (a[i]);
If a[i]>max then max:=a[i];
If a[i]<min then min:=a[i];
End;
WriteLn(' : ',max);
WriteLn(' : ',min);
End.
2. n, 1,...,n. , .
|
|
. , k - . q. (a[i]<>a[i-l]) q . , k (k:=1). q .
. 4.2.
. 4.2. - 2
Turbo Pascal :
Program Count_max;
Const n=10;
a: Array [l..n] of Integer = _
(25,2,2,2,12,17,2,2,2,2);
Var i,k,q: 1..n;
Begin
k:=l; q:=l;
for i:=2 to n do
{ }
if a[i]=a[i-l]
then
Inc(k)
{ }
else
begin
{ q }
if q<k then q:=k;
{ }
k:=l
end;
{ }
if q<k then q:=k;
WriteLn(q);
ReadLn;
End.
3. , n, 1,..., n (n>0). , 1,..., n , . , .
. . . , , . , . , 1) ; 2) . Turbo Pascal, , :
Program Find_1;
Const
x=13; { }
n=10;
a: Array [l..n] of Integer=_
(10,6,55,-1,13,6,29,-80,1,-16);
Var i:1..n;
Begin
i:=l;
While (a[i]<>x) and (i<n) do Inc(i);
If a[i]<>x
Then Write(' ')
Else Write(' : ', i);
End.
. . , . - , (n+1)- , :
Program Find_2;
Const x=13; { }
n=10;
a: Array [1..+1] of Integer=_
(10,6,55,-1,13,6,29,-80,1,-16,);
Var i: 1..n+1;
Begin
i:=l;
While a[i]<>x do Inc(i);
If i=n+l
Then Write(' ')
Else Write(' : ',i);
End.
, , i = n + 1 , , .. . . , .
, Break, . For ( , ).
|
|
Begin
For i:=l to n do
If a[i]=x then Break;
If a[i] <> x
Then Write(' ')
Else Write(' : ',i);
End.
, , , .
4. n, m 1,..., n b1...,bm, . c.
. , . , , , . a[i] b[j] (i-1) (j-1) b, (i+j-2) . , : i+j-1. , . , , .
i+j-1 = i+m+1-1 = i+m, i+j-1 = i+n+1-1 = i+n. , : , a[n]>b[m] , a[n]<b[m].
Turbo Pascal :
Program Conc_mas;
Const n=12;
m=8;
Var a: Array [l..n] of Integer;
b: Array [l..m] of Integer;
c: Array [l..n+m] of Integer;
i,j,k: Integer;
Begin
{ b}
For i:=l to n do a[i]:=i*2;
For j:=l to m do b[j]:=j+9;
{ }
i:=l; j:=l;
While (i<=n) and (j<=m) do
If a[i]<=b[j]
then
begin
[i+j-1]:=a[i];
Inc(i);
End
Else
begin
c[i+j-1]:=b[j];
Inc(j);
End;
While i<=n do
begin
[m+i]:=a[i];
Inc(i);
End;
While j<=m do
begin
[n+j]:=b[j];
Inc(j);
End;
{ }
For k:=l to m+n do Write([k]:8);
ReadLn;
End.
5. n 1, 2,..., n .
. , :
1. .
2. .
3. .
- ( : 1<2<...<n). , . - .
1. .
, , , ai. , . , i i-1, i-2,... , i, . , .
1000 [100, 999]. - , . , , 0, , .. . 0..n. j -, . , . 4.3.
|
|
Turbo Pascal :
Program Sort_mas_1;
Uses Crt;
Const
n=1000;
Var
a: Array [0..n] of _ Integer;
x,j,i: Integer;
Begin
Randomize; {[100, 999]}
For i:=l to n do
begin
a[i]:=100+Random(900);
Write(a[i]:3);
End;
WriteLn;
. 4.3. - 5 (1)
For i:=2 to n do
begin
{x - }
x:=a[i];
{a [0] - }
a[0]:=a[i];
{j- -}
j:=i;
While x<a[j-l] do
begin
a[j]:=a[j-1];
Dec(j)
End;
{ }
a[j]:=x
End;
WriteLn;
For i:=l to n do
Write(a[i]:3);
ReadLn;
End.
2. .
. n - 1 .. , . :
For i:=l to n-1 do
Begin
k:=i;
x:=a[i];
For j:=i+l to n do
If a[j]<x then
begin
k:=j;
x:=a[k]
End;
a[k]:=a[i];
a[i]:=x
End;
. 4.4. - 5 (2)
3. .
, . . " " , , "" . , :
For i:=2 to n do
For j:=n downto i do
If a[j-1]>a[j]
then
Begin {}
x:=a[j-l];
a[j-1]:=a[j];
a[j]:=x
End;
. 4.5. - 5 (3)