program Hello; uses Crt, Math, Sysutils, StrUtils, System; Function pwr(x: Real; y: Real): Real; Var rs: Real; Begin rs := 1; while(y > 0) do Begin rs := rs * x; y := y - 1; End; pwr := rs End; Function BinToDec(binary: String): Real; Var i, pw: Integer; dec: Real; Begin dec := 0; pw := 0; for i:= length(binary) downto 1 do begin dec := dec + ((pwr(2, pw)) * StrToInt(binary[i])); Inc(pw); End; BinToDec := dec; End; var binary, secret: String; i: Integer; dec: Real; pw: Integer; secrets: array of AnsiString; begin writeln ('Awesome binary converter'); binary := '10110100'; secret := '01010100 00100111 01100101 01110011 00100000 01100011 01110101 01110010 01101001 01100101 01110101 01111000 00100000 01110100 01101111 01101001 00100000 00111010 00101001'; pw := 0; //Writeln(pwr(2, 5):0:2); //exit(); secrets := strutils.SplitString(secret, ' '); Writeln('length = ', length(secrets)); dec := BinToDec(binary); Writeln(dec:0:0); end.
Write, Run & Share Pascal code online using OneCompiler’s Pascal online compiler for free. It’s a straightforward, accessible way to learn and experiment with Pascal programming right from your browser. OneCompiler supports modern Pascal syntax and provides a ready-to-use editor for immediate execution.
Pascal is a procedural programming language developed in the 1970s by Niklaus Wirth. It was designed to encourage good programming practices and structured programming. Pascal is widely used in teaching computer science fundamentals and has influenced many modern languages.
The following is a simple Pascal program that prints a greeting:
program HelloWorld;
begin
writeln('Hello, OneCompiler!');
end.
OneCompiler’s Pascal editor supports stdin through the I/O tab. Here’s an example that reads a user's name and prints a greeting:
program GreetUser;
var
name: string;
begin
readln(name);
writeln('Hello, ', name, '!');
end.
var
age: integer;
name: string;
score: real;
flag: boolean;
Type | Description |
---|---|
integer | Whole numbers |
real | Floating-point numbers |
char | Single character |
string | Sequence of characters |
boolean | True or False |
if score >= 50 then
writeln('Pass')
else
writeln('Fail');
for i := 1 to 5 do
writeln(i);
i := 1;
while i <= 5 do
begin
writeln(i);
i := i + 1;
end;
i := 1;
repeat
writeln(i);
i := i + 1;
until i > 5;
procedure SayHello;
begin
writeln('Hello!');
end;
function Add(a, b: integer): integer;
begin
Add := a + b;
end;
This guide provides a quick reference to Pascal programming syntax and features. Start coding in Pascal using OneCompiler’s Pascal online compiler today!