Bài 2:
uses crt;
var s:string;
i,d,dem:integer;
begin
clrscr;
write('Nhap xau S:'); readln(s);
d:=length(s);
dem:=0;
for i:=1 to d do
if st[i]=#32 then inc(dem);
writeln(dem);
readln;
end.
Bài 1:
Uses crt;
Var i,n,dem:integer;
a:array[1..100] of integer;
Begin
Clrscr;
Write('Nhap do dai cua day A khong qua 100 phan tu: ');readln(n);
While n>100 do
Begin
Write('Nhap lai: ');
readln(n);
end;
dem:=0;
Writeln('Nhap ',n,' phan tu:');
For i:= 1 to n do
Begin
Write('a[',i,'] = ');
readln(a[i]);
If a[i] mod 2 = 1 then inc(dem);
end;
Writeln('Day co ',dem,' phan tu le');
readln;
End.
Bài 2:
Uses crt;
Var i,dem:integer;
s:string;
Begin
Clrscr;
Write('Nhap S khong qua 100 ki tu: ');readln(s);
While length(s)>100 do
Begin
Write('Nhap lai: ');
readln(s);
end;
dem:=0;
For i:= 1 to length(s) do If s[i] = ' ' then inc(dem);
Writeln('Xau vua nhap co ',dem,' ki tu trang');
readln;
End.