program abc; uses crt; const bk=['A'..'Z','a'..'z','А'..'я','ё','Ё']; function letters(s:string;i:integer):integer; var k:integer; begin if s[i] in bk then inc(k); if i<length(s) then k:=k+letters(s,i+1); letters:=k; end; var s:string; begin writeln('Введите строку:'); readln(s); write('Количество букв=',letters(s,1)) end.
Другая реализация функции:
Function num_lett(s : string) : integer; Var l : integer; Begin l:=length(s); if l=0 then num_lett:=0 else if s[1] in bk then num_lett:=1+num_lett(copy(s,2,l)) else num_lett:=num_lett(copy(s,2,l)); End;
Комментариев нет:
Отправить комментарий