Цитата:
Сообщение от ВасилийНемтырев
Надеюсь на вашу помощь))
|
Постараюсь оправдать.
Цитата:
Сообщение от ВасилийНемтырев
1)Написать программу, которая подсчитывает количество слов, начинающихся на заданную букву в созданном тестовом файле.
|
Код:
Const
Nw=100; {Number of words in file}
Var
f:Text;
i,N:Word;
j,Nl:Byte;
C,C1:Char;
Begin
Randomize;
{Creating the text file}
Assign(f,'Story.txt');
Rewrite(f);
For i:=1 to Nw do
begin
Nl:=Random(16)+1; {Length of the word}
for j:=1 to Nl do
write(f,Chr(97+random(26)));
if i<Nw then write(f,' ');
end;
Close(f);
Reset(f);
{Show the file on the screen}
Repeat
read(f,C);
write(C);
Until EoF(f);
Writeln;
Writeln;
Write('The letter (small Latin) to search: ');
Readln(C1);
Writeln;
N:=0;
Reset(f);
Repeat
Read(f,C);
If C=' ' then
begin
read(f,C);
if C=C1 then Inc(N);
end;
Until EoF(f);
Writeln(N,' times');
Readln
End.
Цитата:
Сообщение от ВасилийНемтырев
2)Написать программу, которая выводит на экран те компоненты файла последовательного доступа, которые делятся на m , но не делятся на n . Подсчитать их количество.
|
Код:
Const
Nn=100; {Amount of numbers in file}
Var
f:file of Integer;
m,n,C:Integer;
i,Nx:Byte;
Begin
Randomize;
{Creating the file}
Assign(f,'Num.dat');
Rewrite(f);
For i:=1 to Nn do
begin
C:=32000-Random(64000);
Write(f,C);
end;
Close(f);
{Show the file on the screen}
Reset(f);
For i:=1 to Nn do
begin
read(f,C);
write(C:8);
end;
Writeln;
Writeln;
Write('m= ');
Readln(m);
Write('n= ');
Readln(n);
Nx:=0;
Reset(f);
for i:=1 to Nn do
begin
read(f,C);
if ((C mod m)=0) and ((C mod n)<>0) then Inc(Nx);
end;
Close(f);
Writeln(Nx,' numbers');
Readln
End.