Professional Documents
Culture Documents
Pascal Sample Programs
Pascal Sample Programs
readln(); exit;
end. end;
end;
end.
Program to compute Factorial using
Recursive Function
Program to check for Palindrome
program FactorialOfAnyNumber;
var program Palindrone;
numInput, result:integer; uses crt;
var
function Factorial(num:integer):integer; s:string;
var backward:string;
count,fac : integer; x:integer;
begin
if (num = 0) then begin
Factorial := 1 Writeln('Enter String');
else readln(s);
Factorial := num * Factorial(num - 1); s:=Lowercase(s);
end; for x:=length(s) downto 1 do
backward:= backward+ s[x];
begin clrscr;
writeln('Enter Any number:'); Writeln('The String forwards: ', s);
readln(numInput); Writeln('The String backwards: ', backward);
public
constructor create(t, p: string);
procedure setprice(p: string);
function getprice(): string;
procedure settitle(t: string);
function gettitle(): string;
procedure display;
end;
3
var
myBook: Book;
procedure Book.display;
begin
Writeln('Book Title: ',title);
Writeln('Book Price: ',price);
end;
begin
myBook:= Book.create('500', 'Feature
Engineering');
writeln('New Book: ', myBook.getprice(), ' by
' , myBook.gettitle());
myBook.setprice('300');
myBook.settitle('Machine Learning');
myBook.display;
end.