Задача 1 Урок 17
Primary tabs
Пользователь вводит символ k
и строку s
-- посчитайте сколько раз символ k
встречается в строке s
var s: string; i, n: integer; begin writeln('enter an arbitrary string'); readln(s); n := 0; // значение по умолчанию (инициализация переменной) for i:=1 to length(s) do // обходим символы строки begin if (s[i] = 'k') then // сравниваем очередной символ строки с литералом n := n + 1; end; writeln('the character K occurs ', n, ' times in a string'); readln(); end.
Вывод консоли:
enter an arbitrary string k the character K occurs 1 times in a string
- Log in to post comments
- 111 reads