Change Character

Posted on 11.06.2010

0


program _changechar;

{
input  : ABC cBa
output : abc CbA
}

uses crt;
var
    frase, _tmp : string;
    i, p, nilai : integer;

begin
    clrscr;
    write(‘Input Kata –> ‘); readln(frase);

{ cek karakter }
{ a=97 .. z=122 }
{ A=65 .. Z=90 }

    i:=1;
    p:=length(frase);
    _tmp:=frase;
    while(i<p+1) do
    begin
       nilai:=ord(_tmp[i]);
       case nilai of
          97..122 : frase[i]:=upcase(_tmp[i]);
          65..90 : frase[i]:=char(nilai+32);
       end;
       inc(i);
    end;

    writeln('INPUT : ', _tmp);
    writeln('OUTPUT : ', frase);
    readln;
end.

Posted in: Pascal Code