top of page

Tipul de date String

 

1. De alcatuit un program ce va inlocui caracterul 'V','v' cu 'A','a' intr-un text.

Program P1;

uses crt;

var s:string;

begin

clrscr;

textcolor(3);

textbackground(7);

write(' Introdu textul: ');

readln(s);

for i:=1 to length(s) do

begin

if s[i]='V' then

begin

delete(s,i,1);

insert('A',s,i);

end;

if s[i]='v' then

begin

delete(s,i,1);

insert('a',s,i);

end;

end;

writeln('Text modificat: ',s);

readkey;

end.

2. De alcatuit un program care va afisa cate caractere 'M','m' sunt intr-un text.

Program P2;

uses crt;

var s:string;

nr,i;integer;

begin

clrscr;

textcolor(4);

textbackground(5);

write(' Introdu textul: ');

readln(s);

nr:=0;

for i:=1 to length(s) do

case s[i] of 'm','M':

inc(nr);

end;

writeln('Nr. de litere "m","M": ',nr);

readkey;

end.

3. De alcatuit un program care va afisa de cate ori se intalneste cuvantul "mar" intr-un text.

Program P3;

uses crt;

var s:string;

nr,i;integer;

begin

clrscr;

textcolor(4);

textbackground(5);

write(' Introdu textul: ');

readln(s);

nr:=0;

for i:=1 to length(s) do

if copy(s,i,3)='mar' then

inc(nr);

writeln('Nr. de cuvinte "mar" in text: ',nr);

readkey;

end.

© Creat in 2015 de Mirela. Toate drepturile rezervate!!

bottom of page