Середовище програмування MADL

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Середовище програмування MADL » PascalGUI » PascalGUI.Приклади з Pascal N-IDE » Вихідні коди прикладів з Pascal N-IDE


Вихідні коди прикладів з Pascal N-IDE

Сообщений 1 страница 100 из 104

1

2

uBASIC\Continue_command.pas

Код:
Program Example86;

{ Program to demonstrate the Continue function. }

Var
  I : longint;

begin
  I := 0;
  While I < 10 Do
  begin
    Inc(I);
    If I < 5 Then
      Continue;
    Writeln (i);
  end;
  I := 0;
  Repeat
    Inc(I);
    If I < 5 Then
      Continue;
    Writeln (i);
  Until I >= 10;
  For I:=1 to 10 do
  begin
    If I < 5 Then
      Continue;
    Writeln (i);
  end;
end.

https://forumstatic.ru/files/001b/d4/a7/20718.txt

3

uBASIC\Enum_type.pas

Код:
program exEnumeration;
type
  beverage = (coffee, tea, milk, water, coke, limejuice);

var
  drink : beverage;

begin
  writeln('Which drink do you want?');
  drink := limejuice;

  writeln('You can drink ', drink);
end.
{https://www.tutorialspoint.com/pascal/pascal_variable_types.htm}

https://forumstatic.ru/files/001b/d4/a7/42588.txt

4

uBASIC\File_writer.pas

Код:
var
  f : text;
  i : Integer;
begin
  //open file for ouput
  assign(f, 'file.out');
  rewrite(f);

  //write data
  for i := 1 to 1000 do
  begin
    write(f, random(i), ' ');
    writeln(f);
  end;

  //close file
  close(f);
end.

https://forumstatic.ru/files/001b/d4/a7/70462.txt

5

uBASIC\Set_type.pas

Код:
var
  a : set of Char;
begin
  a := ['a', 'v', 's'];
end.

https://forumstatic.ru/files/001b/d4/a7/92000.txt

6

uBASIC\With_command.pas

Код:
type
  student = record
    name : string;
    address : string;
    grade : integer;
  end;

var
  s : student;

function getInfo(s : student) : string;
begin
  exit('name: ' + s.name + '; address: ' + s.address);
end;

begin
  with s do
  begin
    name := 'John';
    address := 'main street';
    grade := 20;
  end;

  writeln(getInfo(s));

  s.name := 'John';
  s.address := 'main street';
  s.grade := 20;

  writeln(getInfo(s));
end.

https://forumstatic.ru/files/001b/d4/a7/25411.txt

7

uBASIC\array.pas

Код:
program array_example;
var
  simpleArray : array[1..3] of integer;
  complexArray : array[1..3, 1..3] of integer;
  arrayOfString : array[-3..-1] of string;
  i, j : integer;
begin
  {set value for simpleArray}
  for i:=2 to 3 do simpleArray[i] := i * i;
  {write to console}
  for i:=1 to 3 do writeln(simpleArray[i]);
  {set text for complexArray}
  for i:=2 to 3 do
    for j:=1 to 2 do complexArray[i, j] := i * j;
  writeln('complex array:');
  {write to console}
  for i:=1 to 3 do for j:=1 to 3 do writeln('[', i, ',', j, ']=', complexArray[i, j]);

  arrayOfString[-2] := 'hello pascal';
  writeln(arrayOfString[-3], arrayOfString[-2]);
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/66036.txt

8

uBASIC\case_of_statement.pas

Код:
program case_of_statement;
var
  n : integer;
begin
  repeat
    write('Enter number smaller than 5 (n <= 4) : ');
    readln(n);
    if n > 4 then
    begin
      writeln(n, '>', 4);
      writeln('Retry !');
    end;
  until n <= 4;
  case n of
    0 : writeln('zero');
    1 : writeln('one');
    2 : writeln('two');
    3 : writeln('three');
    4 : writeln('four');
  end;
  readln;
end.
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/38328.txt

9

uBASIC\command_break.pas

Код:
{This is a propram used to test "break" command
Used in loops, include:
    for..to...do..
    for..downto..do..
    while...do...
    repeat...until...
}
program break_command;
var
  i : Integer;
begin
  WriteLn('Test break in for..to..do statement: ');
  for i := 1 to 10 do
  begin
    Write(i, ' ');
    if i = 5 then
    begin
      WriteLn('Breaked');
      break;
    end;
  end;
  WriteLn();
  WriteLn('Test break in while..do statement: ');
  i := 1;
  while i < 10 do
  begin
    Write(i, ' ');
    i := i + 1;
    if i = 5 then
    begin
      WriteLn('Breaked');
      break;
    end;
  end;
  WriteLn();
  WriteLn('Test break in repeat...until statement: ');
  i := 1;
  repeat
    Write(i, ' ');
    if i = 5 then
    begin
      WriteLn('Breaked');
      break;
    end;
    inc(i);
  until i = 10;
  {pause screen}
  WriteLn('End of test');
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/30902.txt

10

uBASIC\command_exit.pas

Код:
program command_exit;

procedure func;
begin
  WriteLn('Before exit');
  exit;
  WriteLn('After exit');
end;

begin
  func;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/57577.txt

11

uBASIC\const.pas

Код:
program constant;
const
  a = 10;
    //integer constant
  s = 'pascal';
    //string constant
  c = 'c';
    //char constant
  d : string[10] = 'asdhashdhasdhashd';
    //string constant
  e : integer = 100;
    //integer constant
  f : longint = 12112312;
    //longint constant
  g : real = 1.2;
    //real constant
  i = 1.2;
//real constant
  k = true;
    //boolean constant
  m : boolean = true and false; //boolean constant

begin
  readln;
end.
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/52539.txt

12

uBASIC\dynamic_array.pas

Код:
program dynamic_array;
var
  a : array of array of integer;
    (* a 2 dimensional array *)
  i, j : integer;

begin
  setlength(a, 5, 5);

  for i:=0 to 4 do
    for j:=0 to 4 do
      a[i, j] := i * j;
  setlength(a, 6, 6);
  for i:=0 to 5 do
  begin
    for j:= 0 to 5 do
      write(a[i, j]: 2, ' ');
    writeln;
  end;
end.

https://forumstatic.ru/files/001b/d4/a7/59939.txt

13

uBASIC\file_reader.pas

Код:
var
  fi, fo : text;
  data : string;

begin
  //write data to file 'file.inp'
  Assign(fo, 'file.inp');
  Rewrite(fo);
  Writeln(fo, 'test data');
  Close(fo);

  //read data from file 'file.inp'
  Assign(fi, 'file.inp');
  Reset(fi);
  ReadLn(fi, data);
  close(fi);

  //write to screen
  WriteLn(data);
end.

https://forumstatic.ru/files/001b/d4/a7/90311.txt

14

uBASIC\for_downto_statement.pas

Код:
program for_downto_statement;
var
  i, n : integer;
begin
  writeln('Enter small number: ');
  readln(n);
  for i := n downto 1 do writeln('i = ', i);
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/12721.txt

15

uBASIC\for_in_statment.pas

Код:
type
  MonthType = (January, February, March, April,
                May, June, July, August, September,
                October, November, December);
var
  a : array[1..3] of integer = (1, 2, 3);
  b : set of char = ['a', 'c', 'd'];
  c : char;
  i : integer;
  m : MonthType;

begin
  //for each array
  for i in a do write(i, ' '); //1 2 3
  writeln;

  //for each set
  for c in b do write(c, ' '); //a c d
  writeln;

  //for each enum
  for m := January to December do write(m, ' ');
  readln;
end.

https://forumstatic.ru/files/001b/d4/a7/21968.txt

16

uBASIC\for_to_statement.pas

Код:
program for_to_statement;
var
  i, n : integer;
begin
  writeln('Enter small number: ');
  readln(n);
  for i := 1 to n do writeln('i = ', i);
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/91030.txt

17

uBASIC\function.pas

Код:
function get : integer;
begin
  randomize;
  WriteLn('Test function');
  get := random(1000);
end;

begin
  writeln(get);
  readln;
end.

https://forumstatic.ru/files/001b/d4/a7/20305.txt

18

uBASIC\hello.pas

Код:
program hello_world;
begin
  Writeln('Hello World');
  Readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/59311.txt

19

uBASIC\if_else_statment.pas

Код:
program if_else;
var
  num1, num2 : integer;
begin
  writeln('Enter first number: ');
  readln(num1);
  writeln('Enter second number: ');
  readln(num2);
  if (num1 < num2) then
    writeln(num1, ' < ', num2)
  else if (num1 > num2) then
    writeln(num1, ' > ', num2)
  else
    write(num1, ' = ', num2);

  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/54565.txt

20

uBASIC\in_out.pas

Код:
{How to use "Readln" and "Write" procedure}
program test_io;
var
  a : integer;
  n : string;
begin
  write('> Enter your name: ');
  readln(n);
  writeln('Your name is ', n);

  writeln('> Enter your age: ');
  readln(a);
  writeln('Your age is ', a);
  //print multi variable to console
  writeln('Name: ', n, '; Age: ', a);
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/48268.txt

21

uBASIC\output_format.pas

Код:
program test;
uses crt;

var
  i, j : Integer;
begin
  i := 1;
  j := 3;
  writeln(i / j : 3 : 2);
  {Comment...}
end.

https://forumstatic.ru/files/001b/d4/a7/92218.txt

22

uBASIC\procedure.pas

Код:
program test_procedure;

procedure print(s : string);
begin
  writeln('> ', s);
end;

begin
  print('test procedure');
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/80176.txt

23

uBASIC\record.pas

Код:
program length_of_line;
type
  point = record
    startX, startY : Real;
  end;

  line = record
    p1 : point;
    p2 : point;
  end;
var
  mPoint1, mPoint2 : point;
  mLine : line;

{Get length of line}
function getLength(L : line) : real;
var
  result : real;
begin
  Result := sqrt(Sqr(L.p1.startX + L.p2.startX) + Sqr(L.p1.startY + L.p2.startY));
  getLength := Result;
end;

begin
  mPoint1.startX := 1;
  mPoint1.startY := 2;
  mPoint2.startX := 3;
  mPoint2.startY := 5.2;

  mLine.p1 := mPoint1;
  mLine.p2 := mPoint2;

  WriteLn(getLength(mLine));

  readln;
end.

https://forumstatic.ru/files/001b/d4/a7/82993.txt

24

uBASIC\repeat_until_statement.pas

Код:
program repeat_until_statement;
var
  i : integer;
  sum : integer;
BEGIN
  i := 0;
  sum := 0;
  writeln('Sum of 1 to 100 is: ');
  repeat
    inc(i);
    inc(sum, i);
  until i = 100;
  writeln(sum);
  readln;
END.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/43342.txt

25

uBASIC\string_test.pas

Код:
program string_test;
var
  name : string;
  tmp : char;
  i : Integer;
begin
  {print to console}
  writeln('enter your full name (first case): ');

  {Input data into variable name}
  readln(name);

  {print upper case}
  for i := 1 to length(name) do
  begin
    tmp := upcase(name[i]);
    Write(tmp);
  end;

  writeln;
  {tran le duy -> Tran Le Duy}
  name := ' ' + name;
  for i := 1 to Length(name) do
  begin
    if name[i] = ' ' then name[i + 1] := upcase(name[i + 1]);
  end;

  {print to console}
  writeln(name);
  readln;
end.
{Input: tran le duy
Output:
    TRAN LE DUY
    Tran Le Duy}
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/53207.txt

26

uBASIC\while_do_statement.pas

Код:
program while_do_statement;
var
  i : integer;
  sum : integer;
BEGIN
  i := 1;
  sum := 0;
  While i <= 1000 do
  begin
    sum := sum + i;
    i := i + 1;
  end;
  write('Sum of 1 to 1000 is: ');
  write(sum);
  readln;
END.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/38871.txt

27

uCompileProgram\assignment.pas

Код:
{http://wiki.freepascal.org/Programming_Assignment}

(* Author:    Tao Yue
   Date:      19 June 1997
   Description:
      Find the sum and average of five predefined numbers
   Version:
      1.0 - original version
*)

program SumAverage;

const
  NumberOfIntegers = 5;

var
  A, B, C, D, E : integer;
  Sum : integer;
  Average : real;

begin
  (* Main *)
  A := 45;
  B := 7;
  C := 68;
  D := 2;
  E := 34;
  Sum := A + B + C + D + E;
  Average := Sum / NumberOfIntegers;
  writeln ('Number of integers = ', NumberOfIntegers);
  writeln ('Number1 = ', A);
  writeln ('Number2 = ', B);
  writeln ('Number3 = ', C);
  writeln ('Number4 = ', D);
  writeln ('Number5 = ', E);
  writeln ('Sum = ', Sum);
  writeln ('Average = ', Average)
end.

https://forumstatic.ru/files/001b/d4/a7/46825.txt

28

uCompileProgram\Ball.pas

Код:
program Ball;
uses  CRT, GRAPH;

    { Mini-Game | Мини-Игра }

VAR
  X, Y, F : INTEGER;
  G, S : CHAR;

procedure MoveLeft;
begin
  dec(x, 30);
  clearDevice;
  for F:=0 to 20 do
  begin
    circle(x, y, F);
    circle(x, y, F);
    circle(x, y, F);
  end;
  if x < 0 then x := getMaxX;
end;

procedure MoveRight;
begin
  inc(x, 30);
  clearDevice;
  for F:=0 to 20 do
  begin
    circle(x, y, F);
    circle(x, y, F);
    circle(x, y, F);
  end;
  if x > getMaxX then x := 0;
end;

procedure MoveUp;
begin
  dec(y, 30);
  clearDevice;
  for F:=0 to 20 do
  begin
    circle(x, y, F);
    circle(x, y, F);
    circle(x, y, F);
  end;
  if y < 0 then y := getMaxY;
end;

procedure MoveDown;
begin
  inc(y, 30);
  clearDevice;
  for F:=0 to 20 do
  begin
    circle(x, y, F);
    circle(x, y, F);
    circle(x, y, F);
  end;
  if y > getMaxY then y := 0;
end;
var detect:integer=0;
BEGIN
  randomize;
  if getMaxX > getMaxY then exit;
  writeln('Русский | English   (1 | 2)');
  s := readkey;
  if getMaxX > getMaxY then exit;
  if s = '2' then
  begin
    x := getMaxX div 2;
    y := getMaxY div 2;
    initGRAPH(detect, detect, '');
    CursorOFF;
    clrSCR;
    ClearDevice;
    setCOLOR(-6656);
    setTextStyle(0, 0, 5);
    outTextXY(125, 75, 'g');
    outTextXY(50, 177, 'c');
    outTextXY(125, 180, 'v');
    outTextXY(200, 165, 'b');
    setCOLOR(-16743292);
    outTextXY(125, 270, '+');
    setCOLOR(-1);
    for F:=0 to 20 do
    begin
      circle(x, y, F);
      circle(x, y, F);
      circle(x, y, F);
    end;
    setCOLOR(-16758009);
    While True Do
    begin
      if getMaxX > getMaxY then exit;
      g := ReadKEY;
      if getMaxX > getMaxY then exit;
      if g = 'g' then
      begin
        MoveUp;
        MoveUp;
      end else
        if g = 'v' then
        begin
          MoveDown;
          MoveDown;
        end else
          if g = 'c' then
          begin
            MoveLeft;
            MoveLeft;
          end else
            if g = '+' then setCOLOR(random(getMaxColor)) else
              if g = 'b' then
              begin
                MoveRight;
                MoveRight;
              end else write;
    end;
  end
  else if s = '1' then
  begin
    x := round(getMaxX / 2);
    y := round(getMaxY / 2);
    initGRAPH(detect, detect, '');
    CursorOFF;
    clrSCR;
    ClearDevice;
    setCOLOR(-6656);
    setTextStyle(0, 0, 5);
    outTextXY(125, 75, 'н');
    outTextXY(60, 150, 'п');
    outTextXY(125, 230, 'и');
    outTextXY(190, 151, 'о');
    setCOLOR(-16743292);
    outTextXY(125, 320, '+');
    setCOLOR(-1);
    for F:=0 to 20 do
    begin
      circle(x, y, F);
      circle(x, y, F);
      circle(x, y, F);
    end;
    setCOLOR(-16758009);
    While True Do
    begin
      if getMaxX > getMaxY then exit;
      g := ReadKEY;
      if getMaxX > getMaxY then exit;
      if g = 'н' then MoveUp else
        if g = 'и' then MoveDown else
          if g = 'п' then MoveLeft else
            if g = '+' then setCOLOR(random(getMaxColor)) else
              if g = 'о' then MoveRight else write;
    end;
  end else exit;
END.

https://forumstatic.ru/files/001b/d4/a7/37513.txt

29

uCompileProgram\factorial.pas

Код:
program factorial;

function factorial(i : integer) : integer;
begin
  if i = 1 then
    factorial := 1
  else
    factorial := factorial(i - 1) * i;
end;

begin
  write('10! = ', factorial(10));
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/17455.txt

30

uCompileProgram\Fibonacci.pas

Код:
(* Author:    Tao Yue
   Date:      19 July 1997
   Description:
      Find the first 10 Fibonacci numbers
   Version:
      1.0 - original version
*)

{
Problem 1
Find the first 10 numbers in the Fibonacci sequence.
The Fibonacci sequence starts with two numbers: 1 1

Each subsequent number is formed by adding the two numbers before it.
 1+1=2, 1+2=3, 2+3=5, etc. This forms the following sequence:
1 1 2 3 5 8 13 21 34 55 89 144 ...
}

program Fibonacci;

var
  Fibonacci1, Fibonacci2 : integer;
  temp : integer;
  count : integer;

begin
  (* Main *)
  writeln ('First ten Fibonacci numbers are:');
  count := 0;
  Fibonacci1 := 0;
  Fibonacci2 := 1;
  repeat
    write (Fibonacci2: 7);
    temp := Fibonacci2;
    Fibonacci2 := Fibonacci1 + Fibonacci2;
    Fibonacci1 := Temp;
    count := count + 1
  until count = 10;
  writeln;

  (* Of course, you could use a FOR loop or a WHILE loop
     to solve this problem. *)

end.     (* Main *)

https://forumstatic.ru/files/001b/d4/a7/45711.txt

31

uCompileProgram\Input_output.pas

Код:
{http://wiki.freepascal.org/Programming_Assignment_2}

{
Again find the sum and average of five numbers,
but this time read in five integers and display
the output in neat columns.
Refer to the original problem specification if needed.
You should type in the numbers separated by spaces
from the keyboard: 45 7 68 2 34.
The output should now look like this:
Number of integers = 5

Number1:      45
Number2:       7
Number3:      68
Number4:       2
Number5:      34
================
Sum:         156
Average:      31.2
}

(* Author:    Tao Yue
   Date:      19 June 1997
   Description:
      Find the sum and average of five predefined numbers
   Version:
      1.0 - original version
      2.0 - read in data from keyboard
*)

program SumAverage;

const
  NumberOfIntegers = 5;

var
  A, B, C, D, E : integer;
  Sum : integer;
  Average : real;

begin
  (* Main *)
  write ('Enter the first number: ');
  readln (A);
  write ('Enter the second number: ');
  readln (B);
  write ('Enter the third number: ');
  readln (C);
  write ('Enter the fourth number: ');
  readln (D);
  write ('Enter the fifth number: ');
  readln (E);
  Sum := A + B + C + D + E;
  Average := Sum / 5;
  writeln ('Number of integers = ', NumberOfIntegers);
  writeln;
  writeln ('Number1:', A: 8);
  writeln ('Number2:', B: 8);
  writeln ('Number3:', C: 8);
  writeln ('Number4:', D: 8);
  writeln ('Number5:', E: 8);
  writeln ('================');
  writeln ('Sum:', Sum: 12);
  writeln ('Average:', Average: 10 : 1);
end.

https://forumstatic.ru/files/001b/d4/a7/99549.txt

32

uCompileProgram\power_of_two.pas

Код:
(* Author:    Tao Yue
   Date:      13 July 2000
   Description:
      Display all powers of two up to 20000, five per line
   Version:
      1.0 - original version
*)

{
Problem 2
Display all powers of 2 that are less than 20000.
Display the list in a properly formatted manner,
with commas between the numbers. Display five
numbers per line. The output should look like:
    1, 2, 4, 8, 16,
32, 64, 128, 256, 512,
1024, 2048, 4096, 8192, 16384
}

program power_of_two;

const
  numperline = 5;
  maxnum = 20000;
  base = 2;

var
  number : longint;
  linecount : integer;

begin
  (* Main *)
  writeln ('Powers of ', base, ', 1 <= x <= ', maxnum, ':');
  (* Set up for loop *)
  number := 1;
  linecount := 0;
  (* Loop *)
  while number <= maxnum do
  begin
    linecount := linecount + 1;
    (* Print a comma and space unless this is the first
       number on the line *)
    if linecount > 1 then
      write (', ');
    (* Display the number *)
    write (number);
    (* Print a comma and go to the next line if this is
       the last number on the line UNLESS it is the
       last number of the series *)
    if (linecount = numperline) and not (number * 2 > maxnum) then
    begin
      writeln (',');
      linecount := 0
    end;
    (* Increment number *)
    number := number * base;
  end; (* while *)
  writeln;

  (* This program can also be written using a
     REPEAT..UNTIL loop. *)

end.     (* Main *)

https://forumstatic.ru/files/001b/d4/a7/28875.txt

33

uCompileProgram\Towers_of_Hanoi.pas

Код:
{http://wiki.freepascal.org/Programming_Assignment_4}

(* Author:    Tao Yue
   Date:      13 July 2000
   Description:
      Solves the Towers of Hanoi
   Version:
      1.0 - original version
*)

program TowersofHanoi;

var
  numdiscs : integer;

(* *******************************************************)

procedure DoTowers (NumDiscs, OrigPeg, NewPeg, TempPeg : integer);
(* Explanation of variables:
      Number of discs -- number of discs on OrigPeg
      OrigPeg -- peg number of the tower
      NewPeg -- peg number to move the tower to
      TempPeg -- peg to use for temporary storage
*)

begin
  (* Take care of the base case -- one disc *)
  if NumDiscs = 1 then
    writeln (OrigPeg, ' ---> ', NewPeg)
      (* Take care of all other cases *)
  else
  begin
    (* First, move all discs except the bottom disc
       to TempPeg, using NewPeg as the temporary peg
       for this transfer *)
    DoTowers (NumDiscs - 1, OrigPeg, TempPeg, NewPeg);
    (* Now, move the bottommost disc from OrigPeg
       to NewPeg *)
    writeln (OrigPeg, ' ---> ', NewPeg);
    (* Finally, move the discs which are currently on
       TempPeg to NewPeg, using OrigPeg as the temporary
       peg for this transfer *)
    DoTowers (NumDiscs - 1, TempPeg, NewPeg, OrigPeg)
  end
end;

(********************************************************)


begin
  (* Main *)
  write ('Please enter the number of discs in the tower ===> ');
  readln (numdiscs);
  writeln;
  DoTowers (numdiscs, 1, 3, 2)
end.     (* Main *)

https://forumstatic.ru/files/001b/d4/a7/27172.txt

34

uCRT\clrscr.pas

Код:
Program Example8;
uses Crt;

{ Program to demonstrate the ClrScr function. }

begin
  Writeln('Press any key to clear the screen');
  readln;
  ClrScr;
  Writeln('Have fun with the cleared screen');
end.

https://forumstatic.ru/files/001b/d4/a7/67394.txt

35

uCRT\Delay.pas

Код:
Program Example15;
uses Crt;

{ Program to demonstrate the Delay function. }
var
  i : longint;
begin
  WriteLn('Counting Down');
  for i:=10 downto 1 do
  begin
    WriteLn(i);
    {Wait one second}
    Delay(1000);
  end;
  WriteLn('BOOM!!!');
end.
{http://www.freepascal.org/docs-html/rtl/crt/delay.html}

https://forumstatic.ru/files/001b/d4/a7/44835.txt

36

uCRT\Goto_XY.pas

Код:
Program Example6;
uses Crt;

{ Program to demonstrate the GotoXY function. }
begin
  ClrScr;
  GotoXY(10, 10);
  Write('10,10');
  GotoXY(20, 20);
  Write('20,20');
  GotoXY(1, 22);
  readln;
end.
{http://www.freepascal.org/docs-html/rtl/crt/gotoxy.html}

https://forumstatic.ru/files/001b/d4/a7/60050.txt

37

uCRT\high_low_text.pas

Код:
Program high_low_text;
uses Crt;

{ Program to demonstrate the LowVideo, HighVideo, NormVideo functions. }

begin
  LowVideo;
  WriteLn('This is written with LowVideo');
  HighVideo;
  WriteLn('This is written with HighVideo');
  NormVideo;
  WriteLn('This is written with NormVideo');
end.

https://forumstatic.ru/files/001b/d4/a7/29971.txt

38

uCRT\Sound.pas

Код:
Program Example16;
uses Crt;

{ Program to demonstrate the Sound and NoSound function. }

var
  i : longint;
begin
  WriteLn('You will hear some tones from your speaker');
  while (i < 15000) do
  begin
    inc(i, 500);
    Sound(i);
    Delay(100);
  end;
  WriteLn('Quiet now!');
  {Stop noise}
  NoSound;
end.
{http://www.freepascal.org/docs-html/rtl/crt/nosound.html}

https://forumstatic.ru/files/001b/d4/a7/96119.txt

39

uCRT\TextBackGround.pas

Код:
Program ExampleBgColor;

uses Crt;

{ Program to demonstrate the TextBackground function. }

begin
  WriteLn('This is written in with the default background color');
  TextBackground(Green);
  WriteLn('This is written in with a Green background');
  TextBackground(Brown);
  WriteLn('This is written in with a Brown background');
  TextBackground(Blue);
  WriteLn('This is written in with a Blue background');
  TextBackground(Cyan);
  WriteLn('This is written in with a Cyan background');
  TextBackground(Red);
  WriteLn('This is written in with a Red background');
  TextBackground(Magenta);
  WriteLn('This is written in with a Magenta background');
  TextBackground(LightGray);
  WriteLn('This is written in with a LightGray background');
  TextBackground(DarkGray);
  WriteLn('This is written in with a DarkGray background');
  TextBackground(LightBlue);
  WriteLn('This is written in with a LightBlue background');
  TextBackground(LightGreen);
  WriteLn('This is written in with a LightGreen background');
  TextBackground(LightCyan);
  WriteLn('This is written in with a LightCyan background');
  TextBackground(LightRed);
  WriteLn('This is written in with a LightRed background');
  TextBackground(LightMagenta);
  WriteLn('This is written in with a LightMagenta background');
  TextBackground(Yellow);
  WriteLn('This is written in with a Yellow background');
  TextBackground(Black);
  WriteLn('Back with a black background');
  ReadLn;

end.
{http://www.freepascal.org/docs-html/rtl/crt/textbackground.html}

https://forumstatic.ru/files/001b/d4/a7/17337.txt

40

uCRT\TextColor.pas

Код:
Program ExampleTextColor;
uses Crt;

{ Program to demonstrate the TextColor function. }

begin
  WriteLn('This is written in the default color');
  TextColor(Red);
  WriteLn('This is written in Red');
  TextColor(White);
  WriteLn('This is written in White');
  TextColor(LightBlue);
  WriteLn('This is written in LightBlue');
  TextColor(Green);
  WriteLn('This is written in Green');
  TextColor(Brown);
  WriteLn('This is written in Brown');
  TextColor(Blue);
  WriteLn('This is written in Blue');
  TextColor(Cyan);
  WriteLn('This is written in Cyan');
  TextColor(Red);
  WriteLn('This is written in Red');
  TextColor(Magenta);
  WriteLn('This is written in Magenta');
  TextColor(LightGray);
  WriteLn('This is written in LightGray');
  TextColor(DarkGray);
  WriteLn('This is written in DarkGray');
  TextColor(LightBlue);
  WriteLn('This is written in LightBlue');
  TextColor(LightGreen);
  WriteLn('This is written in LightGreen');
  TextColor(LightCyan);
  WriteLn('This is written in LightCyan');
  TextColor(LightRed);
  WriteLn('This is written in LightRed');
  TextColor(LightMagenta);
  WriteLn('This is written in LightMagenta');
  TextColor(Yellow);
  WriteLn('This is written in Yellow');
  TextColor(Black);
  WriteLn('This is written in Black');
  ReadLn;
end.
{http://www.freepascal.org/docs-html/rtl/crt/textcolor.html}

https://forumstatic.ru/files/001b/d4/a7/90980.txt

41

uCRT\WhereXY.pas

Код:
Program Example7;
uses Crt;

{ Program to demonstrate the WhereX and WhereY functions. }

begin
  Writeln('Cursor postion: X=', WhereX, ' Y=', WhereY);
end.
{http://www.freepascal.org/docs-html/rtl/crt/wherex.html}

https://forumstatic.ru/files/001b/d4/a7/32198.txt

42

uDOS\GetDate.pas

Код:
Program Example2;
uses Dos;

{ Program to demonstrate the GetDate function. }

const
  DayStr : array[0..6] of string[3] = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  MonthStr : array[1..12] of string[3] = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var
  Year, Month, Day, WDay : word;
begin
  GetDate(Year, Month, Day, WDay);
  WriteLn('Current date');
  WriteLn(DayStr[WDay], ', ', Day, ' ', MonthStr[Month], ' ', Year, '.');
end.

https://forumstatic.ru/files/001b/d4/a7/74487.txt

43

uDOS\GetTime.pas

Код:
program GetTime1;
uses dos, crt;

var
  a, b, c, d : word;

function print(w : integer) : string;
var
  s : string;
begin
  Str(w, s);
  if w < 10 then
    print := '0' + s
  else
    print := s;
end;

begin
  while not keyPressed do
  begin
    clrscr;
    GetTime(a, b, c, d);
    gotoXY(15, 8);
    textColor(White);
    WriteLn('Current time');
    gotoXY(17, 9);
    textColor(Yellow);

    WriteLn(print(a), ':', print(b), ':', print(c));
    delay(1000);
  end;
  readln;
end.
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/17866.txt

44

uDOS\PackTime.pas

Код:
Program Example4;
uses Dos;

{ Program to demonstrate the PackTime and UnPackTime functions. }

var
  DT : DateTime;
  Time : longint;
begin
  with DT do
  begin
    Year := 2017;
    Month := 11;
    Day := 11;
    Hour := 11;
    Min := 11;
    Sec := 11;
  end;
  PackTime(DT, Time);
  WriteLn('Packed Time : ', Time);
  UnPackTime(Time, DT);
  WriteLn('Unpacked Again:');
  with DT do
  begin
    WriteLn('Year  ', Year);
    WriteLn('Month ', Month);
    WriteLn('Day   ', Day);
    WriteLn('Hour  ', Hour);
    WriteLn('Min   ', Min);
    WriteLn('Sec   ', Sec);
  end;

//  readln;
end.

https://forumstatic.ru/files/001b/d4/a7/90051.txt

45

uGraph\Arc.pas

Код:
Program draw_arc;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  SetColor(Random(15) + 1); {Set paint color}

  {Draw arc}
  arc(200, 200, 0, 90, 100);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/88483.txt

46

uGraph\Bar.pas

Код:
Program draw_bar;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');
  Randomize;
  SetColor(Random(15) + 1); {Set paint color}


  {Draw bar}
  bar(100, 100, 300, 200);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/38677.txt

47

uGraph\Bar3d.pas

Код:
Program Graphika12;
Uses Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');
  setcolor (5);
  setlinestyle(2, 0, 3);
  setfillstyle (6, 7);
  bar3d (100, 100, 300, 500, 50, topoff);
  readln;
  closegraph;
end.


https://forumstatic.ru/files/001b/d4/a7/22754.txt

48

uGraph\Circle.pas

Код:
program draw_circle;
uses graph;

Var
  graphicsDriver, graphicsMode : integer;
  Radius : Integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');
  setlinestyle(0, 0, 3);

  for Radius:=1 to 23 do Circle(320, 240, Radius * 10);

  readln;
  ClearDevice; {clear screen}

  SetColor(LightMagenta); {set paint color}

  for Radius:=1 to 23 do Arc(320, 240, 0, 280, Radius * 10);

  readln;
  closegraph;

end.

https://forumstatic.ru/files/001b/d4/a7/95405.txt

49

uGraph\Ellipse.pas

Код:
Program ellipse1;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  SetColor(Random(15) + 1); {Set paint color}


  {Draw bar}
  ellipse(200, 200, 0, 270, 200, 100);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/70843.txt

50

uGraph\FillEllipse.pas

Код:
Program draw_fill_ellipse;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  SetColor(Random(15) + 1); {Set paint color}

  fillEllipse(200, 200, 150, 50);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/32192.txt

51

uGraph\FloodFill.pas

Код:
uses graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  setFillStyle(3, Blue);
  Bar3D(150, 130, 440, 470, 100, topon);

  FloodFill(300, 125, Cyan);
  readln;
  closegraph;
end.

https://forumstatic.ru/files/001b/d4/a7/54300.txt

52

uGraph\GetImage.pas

Код:
uses Graph;

var
  P : Pointer;
  Size : Word;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  SetFillStyle(XHatchFill, Cyan);
  Bar(0, 0, GetMaxX, GetMaxY);
  Size := ImageSize(10, 20, 30, 40);
  GetMem(P, Size);
  GetImage(10, 20, 30, 40, P^);
  ReadLn;
  ClearDevice;
  PutImage(100, 100, P^, NormalPut);
  ReadLn;
  CloseGraph;
end.
{http://pascal.net.ru/GetImage}

https://forumstatic.ru/files/001b/d4/a7/14961.txt

53

uGraph\Graph_fill.pas

Код:
Uses Graph, CRT;

var
  d, r, k, j, x, y : Integer;
begin

  d := Detect;
  InitGraph(d, r, ' ');


  x := GetMaxX div 6; {Положение графика}
  y := GetMaxY div 5; {на экране}
  for j := 0 to 2 do{Два ряда}
    for k := 0 to 3 do{По четыре квадрата}
    begin
      Rectangle((k + 1) * x, (j + 1) * y, (k + 2) * x, (j + 2) * y);
      SetFillStyle(k + j * 4, j + 1);
      Bar((k + 1) * x + 1, (j + 1) * y + 1, (k + 2) * x - 1, (j + 2) * y - 1)
    end;
  ReadLn();
  CloseGraph;

end.

https://forumstatic.ru/files/001b/d4/a7/26002.txt

54

uGraph\Line.pas

Код:
Program draw_line;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode,
    i, startX, startY, maxColor, color : Integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  startX := getMaxX();
  startY := getMaxY();
  maxColor := getMaxColor();

  While (not keypressed) do
  Begin
    delay(50);
    color := random(maxColor) + 1;
    setColor(color);
    line(random(startX), random(startY), random(startX), random(startY));
  end;

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/40788.txt

55

uGraph\Line_style.pas

Код:
Program line_style;
uses Graph;

var
  Gd, Gm : Integer;
  X1, Y1, X2, Y2 : Integer;
begin
  Gd := Detect;
  InitGraph(Gd, Gm, ' ');

  SetColor(blue);

  //    draws a solid line.
  SetLineStyle(SolidLn, 0, ThickWidth);
  rectangle(10, 10, 300, 110);

  //    Draws a dotted line.
  SetLineStyle(DottedLn, 0, ThickWidth);
  rectangle(10, 120, 300, 220);

  //    draws a non-broken centered line.
  SetLineStyle(CenterLn, 0, ThickWidth);
  rectangle(10, 230, 300, 330);

  //    draws a dashed line.
  SetLineStyle(DashedLn, 0, ThickWidth);
  rectangle(10, 340, 300, 440);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/12850.txt

56

uGraph\Move_to.pas

Код:
program moveToExample;
Uses Graph;

Var
  Gd, Gm : Integer;
Begin
  Gd := Detect;
  InitGraph(Gd, Gm, '');

  MoveTo(0, 0);
  LineTo(GetMaxX, GetMaxY);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/43152.txt

57

uGraph\OutText.pas

Код:
Program outtext_sample;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode : integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  SetColor(Random(15) + 1); {Set text color}

  OutTextXY(20, 20, 'Welcome to the new generation of Pascal Programming:');
  OutTextXY(20, 30, 'Pascal Graphics!!');
  OutTextXY(25, 70, 'You will learn more graphics procedures and');
  OutTextXY(25, 80, 'functions, later in this lesson :-)');

  Readln;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/28867.txt

58

uGraph\PieSlice.pas

Код:
{Sample code for the PieSlice procedure.}
uses Graph;

const
  Radius = 30;
var
  Gd, Gm : Integer;
begin
  Gd := Detect;
  InitGraph(Gd, Gm, ' ');

  PieSlice(100, 100, 0, 270, Radius);
  Readln;
  CloseGraph;
end.
{http://putka.upm.si/langref/turboPascal/04B7.html}

https://forumstatic.ru/files/001b/d4/a7/69328.txt

59

uGraph\putPixel.pas

Код:
program draw_pixel;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode,
    color, maxColor, startX, startY : Integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  startX := getMaxX;
  startY := getMaxY;
  maxColor := getMaxColor;

  randomize;
  While (not keypressed) do
  Begin
    color := random(maxColor) + 1;
    putPixel(random(startX), random(startY), color);
  end;
  Closegraph;
End.

https://forumstatic.ru/files/001b/d4/a7/88359.txt

60

uGraph\Rect.pas

Код:
Program rect;
Uses Crt, Graph;

Var
  graphicsDriver, graphicsMode, i : Integer;
Begin
  graphicsDriver := Detect;
  InitGraph(graphicsDriver, graphicsMode, '');

  Randomize;
  SetColor(Random(15) + 1); {Set text color}

  rectangle(10, 10, 200, 200);

  ReadLn;
  CloseGraph;
End.

https://forumstatic.ru/files/001b/d4/a7/85214.txt

61

uGraph\Sector.pas

Код:
{Sample code for the Sector procedure.}
uses Graph;

const
  R = 50;
var
  Driver, Mode : Integer;
  Xasp, Yasp : Word;
begin
  Driver := Detect; { Put in graphics mode }
  InitGraph(Driver, Mode, ' ');

  Sector(GetMaxX div 2, GetMaxY div 2, 0, 234, R, R);

  Readln;
  CloseGraph;
end.
{http://putka.upm.si/langref/turboPascal/04D0.html}

https://forumstatic.ru/files/001b/d4/a7/97870.txt

62

uGraph\Text_align.pas

Код:
uses Graph;

var
  Gd, Gm : Integer;

begin
  Gd := Detect;
  InitGraph(Gd, Gm, '');

  SetTextJustify(CenterText, CenterText);
  OutTextXY(Succ(GetMaxX) div 2, Succ(GetMaxY) div 3, 'CenterText');

  SetTextJustify(LeftText, CenterText);
  OutTextXY(0, Succ(GetMaxY) div 3, 'LeftText');

  SetTextJustify(RightText, CenterText);
  OutTextXY(Succ(GetMaxX), Succ(GetMaxY) div 3, 'RightText');
  ReadLn;
  CloseGraph;
end.

https://forumstatic.ru/files/001b/d4/a7/57778.txt

63

uGraph\Text_size.pas

Код:
uses Graph;

var
  Gd, Gm : Integer;
  Row : Integer;
  Title : String;
  Size : Integer;

begin
  Gd := Detect;
  InitGraph(Gd, Gm, '');

  Row := 0;
  Title := 'Turbo Graphics';
  Size := 1;
  while TextWidth(Title) < GetMaxX do
  begin
    OutTextXY(0, Row, Title);
    Inc(Row, TextHeight('M'));
    Inc(Size);
    SetTextStyle(DefaultFont, HorizDir, Size);
  end;
  ReadLn;
  CloseGraph;
end.

{http://pascal.net.ru/TextWidth}

https://forumstatic.ru/files/001b/d4/a7/24129.txt

64

uMath\Acrcos.pas

Код:
Program Example1;

{ Program to demonstrate the arccos function. }

Uses math;

Procedure WriteRadDeg(X : float);

begin
  Writeln(X: 8 : 5, ' rad = ', radtodeg(x): 8 : 5, ' degrees.')
end;

begin
  WriteRadDeg (arccos(1));
  WriteRadDeg (arccos(sqrt(3) / 2));
  WriteRadDeg (arccos(sqrt(2) / 2));
  WriteRadDeg (arccos(1 / 2));
  WriteRadDeg (arccos(0));
  WriteRadDeg (arccos(-1));
end.
{https://www.freepascal.org/docs-html/rtl/math/arccos.html}

https://forumstatic.ru/files/001b/d4/a7/44864.txt

65

uMath\Acrcosh.pas

Код:
Program Example3;

{ Program to demonstrate the arcosh function. }

Uses math;

begin
  Writeln(arcosh(1) : 0 : 6);
  Writeln(arcosh(2) : 0 : 6);
end.

https://forumstatic.ru/files/001b/d4/a7/95959.txt

66

uMath\asinh.pas

Код:
Program Example4;

{ Program to demonstrate the arsinh function. }

Uses math;

begin
  Writeln(arsinh(0));
  Writeln(arsinh(1));
end.
{https://www.freepascal.org/docs-html/rtl/math/arsinh.html}

https://forumstatic.ru/files/001b/d4/a7/53956.txt

67

uMath\atanh.pas

Код:
Program Example5;

{ Program to demonstrate the artanh function. }

Uses math;

begin
  Writeln(artanh(0) : 0 : 5);
  Writeln(artanh(0.5) : 0 : 5);
end.
{https://www.freepascal.org/docs-html/rtl/math/artanh.html}

https://forumstatic.ru/files/001b/d4/a7/77171.txt

68

uMath\ceil.pas

Код:
Program Example13;

{ Program to demonstrate the floor function. }

Uses math;

begin
  Writeln(Ceil(-3.7)); // should be -4
  Writeln(Ceil(3.7)); // should be 3
  Writeln(Ceil(-4.0)); // should be -4
end.

https://forumstatic.ru/files/001b/d4/a7/18911.txt

69

uMath\cicletorad.pas

Код:
Program Example10;

{ Program to demonstrate the cycletorad function. }

Uses math;

begin
  // Should print 1/2
  writeln(cos(cycletorad(1 / 6)));
  // should be sqrt(2)/2
  writeln(cos(cycletorad(1 / 8)));
end.
{http://www.freepascal.org/docs-html/rtl/math/cycletorad.html}

https://forumstatic.ru/files/001b/d4/a7/45723.txt

70

uMath\degtograd.pas

Код:
Program Example11;

{ Program to demonstrate the degtograd function. }

Uses math;

begin
  writeln(degtograd(90));
  writeln(degtograd(180));
  writeln(degtograd(270))
end.
{http://www.freepascal.org/docs-html/rtl/math/degtograd.html}

https://forumstatic.ru/files/001b/d4/a7/40969.txt

71

uMath\power.pas

Код:
Program Example34;

{ Program to demonstrate the power function. }

Uses Math;

procedure dopower(x, y : float);

begin
  writeln(x: 8 : 6, '^', y: 8 : 6, ' = ', power(x, y): 8 : 6)
end;

begin
  dopower(2, 2);
  dopower(2, -2);
  dopower(2, 0.0);
end.

https://forumstatic.ru/files/001b/d4/a7/59134.txt

72

uMath\tanh.pas

Код:
Program Example48;

{ Program to demonstrate the Tanh function. }

Uses math;

begin
  writeln(tanh(0));
  writeln(tanh(1));
  writeln(tanh(-1));
end.
{http://www.freepascal.org/docs-html/rtl/math/tanh.html}

https://forumstatic.ru/files/001b/d4/a7/47766.txt

73

uSYSTEM\Byte.pas

Код:
{This program will be test function "byte"
    function byte(<condition>)
    return 1 if <condition> is true, else return 0
}
program byteFunction;
var
  b : Boolean;
begin
  b := false;
  WriteLn(b, ' ', byte(b));
  b := true;
  WriteLn(b, ' ', byte(b));
  {pause screen}
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/41747.txt

74

uSYSTEM\CharToAscii.pas

Код:
program CharToAscii1;
var
  character : char;
  ascii : integer;
begin
  ascii := ord('a');
  writeln('a in ascii is ', ascii);
  character := chr(87);
  writeln('ascii 87 is character ', character);
  readln;
end.
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/82866.txt

75

uSYSTEM\ConcatString.pas

Код:
Program ConcatString;

{ Program to demonstrate the Concat function. }
Var
  S : String;

begin
  S := Concat('This can be done', ' Easier ', 'with the + operator !');
  WriteLn(s);
end.

https://forumstatic.ru/files/001b/d4/a7/55343.txt

76

uSYSTEM\Copy.pas

Код:
Program Copy1;

{ Program to demonstrate the Copy function. }

Var
  S, T : String;

begin
  T := '1234567';
  S := Copy (T, 1, 2); { S:='12'   }
  writeln(s);
  S := Copy (T, 4, 2); { S:='45'   }
  writeln(s);
  S := Copy (T, 4, 8); { S:='4567' }
  writeln(s);
end.

https://forumstatic.ru/files/001b/d4/a7/83007.txt

77

uSYSTEM\Cos.pas

Код:
Program Cos1;

{ Program to demonstrate the Cos function. }

Var
  R : Real;

begin
  R := Cos(Pi); { R:=-1 }
  writeln(R);
  R := Cos(Pi / 2); { R:=0  }
  WriteLn(R);
  R := Cos(0); { R:=1  }
  WriteLn(R);
end.

https://forumstatic.ru/files/001b/d4/a7/38603.txt

78

uSYSTEM\Dec.pas

Код:
Program Dec1;

{ Program to demonstrate the Dec function. }

Var
  I : Integer;
  L : Longint;
  W : Word;
  B : Byte;
  Si : ShortInt;

begin
  I := 1;
  L := 2;
  W := 3;
  B := 4;
  Si := 5;
  Dec(i); { i:=0  }
  Dec(L, 2); { L:=0  }
  Dec(W, 2); { W:=1  }
  Dec(B, -2); { B:=6  }
  Dec(Si, 0); { Si:=5 }
  Write(i, ' ', L, ' ', W, ' ', B, ' ', Si);
end.

https://forumstatic.ru/files/001b/d4/a7/21775.txt

79

uSYSTEM\Delete.pas

Код:
Program Delete1;

{ Program to demonstrate the Delete function. }

Var
  S : String;

begin
  S := 'This is not easy !';
  Delete (S, 9, 4); { S:='This is easy !' }
  writeln(s);
end.

https://forumstatic.ru/files/001b/d4/a7/90086.txt

80

uSYSTEM\Earse.pas

Код:
Program Example20;

{ Program to demonstrate the Erase function. }

Var
  F : Text;

begin
  { Create a file with a line of text in it}
  Assign (F, 'test.txt');
  Rewrite (F);
  Writeln (F, 'Try and find this when I''m finished !');
  close (f);
  { Now remove the file }
  Erase (f);
end.

https://forumstatic.ru/files/001b/d4/a7/93735.txt

81

uSYSTEM\Eoln.pas

Код:
var
  myFile : TextFile;
  letter : char;
  text : string;

begin
  // Try to open the Test.txt file for writing to
  Assign(myFile, 'Test.txt');
  ReWrite(myFile);

  // Write lines of text to the file
  WriteLn(myFile, 'Hello');
  WriteLn(myFile, 'To you');

  // Close the file
  Close(myFile);

  Reset(myFile);
  while not Eof(myFile) do
  begin
    readln(myFile, text);
    writeln(text);
  end;
  Close(myFile);

  // Reopen the file for reading
  Reset(myFile);

  // Display the file contents
  while not Eof(myFile) do
  begin
    // Proces one line at a time
    writeln('Start of a new line :');
    while not Eoln(myFile) do
    begin
      Read(myFile, letter); // Read and display one letter at a time
      write(letter);
    end;
    ReadLn(myFile, text);
    writeln(text);
  end;

  // Close the file for the last time
  Close(myFile);
end.

{http://www.delphibasics.co.uk/RTL.asp?Name=Eoln}
Result Test.txt:

Hello
To you

https://forumstatic.ru/files/001b/d4/a7/28032.txt

82

uSYSTEM\Exit.pas

Код:
Program Exit1;

{ Program to demonstrate the Exit function. }

Procedure DoAnExit (Yes : Boolean);

{ This procedure demonstrates the normal Exit }

begin
  Writeln ('Hello from DoAnExit !');
  If Yes then
  begin
    Writeln ('Bailing inType early.');
    exit;
  end;
  Writeln ('Continuing to the end.');
end;

Function Positive (Which : Integer) : Boolean;

{ This function demonstrates the extra FPC feature of Exit :
  You can specify a return value for the function }

begin
  if Which > 0 then
    exit (True)
  else
    exit (False);
end;

begin
  { This call will go to the end }
  DoAnExit (False);
  { This call will bail inType early }
  DoAnExit (True);
  if Positive (-1) then
    Writeln ('The compiler is nuts, -1 is not positive.')
  else
    Writeln ('The compiler is not so bad, -1 seems to be negative.');
end.

https://forumstatic.ru/files/001b/d4/a7/47481.txt

83

uSYSTEM\Frac.pas

Код:
Program Frac1;

{ Program to demonstrate the Frac function. }

Var
  R : Real;

begin
  Writeln (Frac (123.456): 0 : 3); { Prints  O.456 }
  Writeln (Frac (-123.456): 0 : 3); { Prints -O.456 }
end.

https://forumstatic.ru/files/001b/d4/a7/22645.txt

84

uSYSTEM\Function.pas

Код:
program testFunc;

//return sqrt(number)
function square_root(a : integer) : real;
begin
  square_root := sqrt(a);
end;

begin
  writeln('sqrt(4) = ', square_root(4));
  readln;
end.
{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/74016.txt

85

uSYSTEM\IncDec.pas

Код:
program IncDec;
var
  a : integer;
begin
  a := 1;
  Write('a = ', a);
  inc(a);
  Writeln('a + 1 = ', a);
  dec(a);
  Writeln('a - 1 = ', a);
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/26331.txt

86

uSYSTEM\Insert.pas

Код:
Program Insert1;

{ Program to demonstrate the Insert function. }

Var
  S : String;

begin
  S := 'Free Pascal is difficult to use !';
  Insert ('NOT ', S, pos('difficult', S));
  writeln (s);
end.

https://forumstatic.ru/files/001b/d4/a7/74746.txt

87

uSYSTEM\Keypressed.pas

Код:
Program Keypressed1;
uses Crt;

{ Program to demonstrate the KeyPressed function. }

begin
  WriteLn('Waiting until a key is pressed');
  repeat
  until KeyPressed;
  { The key is not Read,
    so it should also be outputted at the commandline}
end.
{http://www.freepascal.org/docs-html/rtl/crt/keypressed.html}

https://forumstatic.ru/files/001b/d4/a7/36737.txt

88

uSYSTEM\Length.pas

Код:
Program Length1;

{ Program to demonstrate the Length function. }

type
  somebytes = array [6..10] of byte;

  somewords = array [3..10] of word;

Var
  S : String;
  I : Integer;
  bytes : somebytes;
  words : somewords;

begin
  S := '';
  for i:=1 to 10 do
  begin
    S := S + '*';
    Writeln (Length(S): 2, ' : ', s);
  end;
  Writeln('Bytes : ', length(bytes));
  Writeln('Words : ', length(words));
end.

https://forumstatic.ru/files/001b/d4/a7/93169.txt

89

uSYSTEM\Odd.pas

Код:
Program Example43;

{ Program to demonstrate the Odd function. }

begin
  If Odd(1) Then
    Writeln ('Everything OK with 1 !');
  If Not Odd(2) Then
    Writeln ('Everything OK with 2 !');
end.
{http://www.freepascal.org/docs-html/rtl/system/odd.html}

https://forumstatic.ru/files/001b/d4/a7/17586.txt

90

uSYSTEM\Pos.pas

Код:
Program Pos1;

{ Program to demonstrate the Pos function. }

Var
  S : String;

begin
  S := 'The first space in this sentence is at position : ';
  Writeln (S, pos(' ', S));
  S := 'The last letter of the alphabet doesn''t appear in this sentence ';
  If (Pos ('Z', S) = 0) and (Pos('z', S) = 0) then
    Writeln (S);
end.

https://forumstatic.ru/files/001b/d4/a7/77826.txt

91

uSYSTEM\Random.pas

Код:
program Random1;
var
  i : integer;
begin
  randomize;
  for i := 1 to 10 do
    writeln(random(1000));
  readln;
end.

{if you want to improve this code, please send code to me
tranleduy1233@gmail.com}

https://forumstatic.ru/files/001b/d4/a7/84045.txt

92

uSYSTEM\random2.pas

Код:
Program Example49;

{ Program to demonstrate the Random and Randomize functions. }

Var
  I, Count, guess : Longint;
  R : Real;

begin
  Randomize; { This way we generate a new sequence every time
               the program is generate}
  Count := 0;
  For i:=1 to 1000 do
    If Random > 0.5 then inc(Count);
  Writeln ('Generated ', Count, ' numbers > 0.5');
  Writeln ('inType of 1000 generated numbers.');
  count := 0;
  For i:=1 to 5 do
  begin
    write ('Guess a number between 1 and 5 : ');
    readln(Guess);
    If Guess = Random(5) + 1 then inc(count);
  end;
  Writeln ('You guessed ', Count, ' inType of 5 correct.');
end.

https://forumstatic.ru/files/001b/d4/a7/51576.txt

93

uSYSTEM\ReadKey.pas

Код:
Program ReadKey1;
uses Crt;

{ Program to demonstrate the ReadKey function. }

var
  ch : char;
begin
  writeln('Press a/b, q=Quit');
  repeat
    ch := ReadKey;
    case ch of
      #0 :
      begin
        ch := ReadKey; {Read ScanCode}
        case ch of
          #97 : WriteLn('pressed a');
          #98 : WriteLn('pressed b');
        end;
      end;
      #113 : WriteLn('quit');
    end;
  until ch = #113 {quit}
end.

{More information: https://en.wikipedia.org/wiki/ASCII}

https://forumstatic.ru/files/001b/d4/a7/94200.txt

94

uSYSTEM\Round.pas

Код:
Program Round1;

{ Program to demonstrate the Round function. }

begin
  Writeln (Round(1234.56)); { Prints 1235     }
  Writeln (Round(-1234.56)); { Prints -1235    }
  Writeln (Round(12.3456)); { Prints 12       }
  Writeln (Round(-12.3456)); { Prints -12      }
  Writeln (Round(2.5)); { Prints 2 (down) }
  Writeln (Round(3.5)); { Prints 4 (up)   }

end.

https://forumstatic.ru/files/001b/d4/a7/30956.txt

95

uSYSTEM\SetLength.pas

Код:
var
  a : array of integer;
  i : integer;
begin
  SetLength(a, 10);
  for i := 0 to 9 do
    a[i] := i;
  for i := 0 to 9 do
    writeln('a[', i, ']=', a[i]);
end.

https://forumstatic.ru/files/001b/d4/a7/37122.txt

96

uSYSTEM\Sin.pas

Код:
Program Sin1;

{ Program to demonstrate the Sin function. }

begin
  Writeln (Sin(Pi): 0 : 1); { Prints 0.0 }
  Writeln (Sin(Pi / 2): 0 : 1); { Prints 1.0 }
end.

https://forumstatic.ru/files/001b/d4/a7/12634.txt

97

uSYSTEM\SizeOf.pas

Код:
Program SizeOf1;

{ Program to demonstrate the SizeOf function. }
Var
  I : Longint;
  S : String [10];

begin
  Writeln (SizeOf(I)); { Prints 4  }
  Writeln (SizeOf(S)); { Prints 11 }
end.

https://forumstatic.ru/files/001b/d4/a7/31391.txt

98

uSYSTEM\Sqr.pas

Код:
Program Sqr1;

{ Program to demonstrate the Sqr function. }
Var
  i : Integer;

begin
  For i:=1 to 10 do
    writeln(Sqr(i): 3);
end.

https://forumstatic.ru/files/001b/d4/a7/90954.txt

99

uSYSTEM\Sqrt.pas

Код:
Program Sqrt1;

{ Program to demonstrate the Sqrt function. }

begin
  Writeln (Sqrt(4): 0 : 3); { Prints 2.000 }
  Writeln (Sqrt(2): 0 : 3); { Prints 1.414 }
end.

https://forumstatic.ru/files/001b/d4/a7/95226.txt

100

uSYSTEM\Str.pas

Код:
Program Str1;

{ Program to demonstrate the Str function. }
Var
  S : String;

Function IntToStr (I : Longint) : String;

Var
  S : String;

begin
  Str (I, S);
  IntToStr := S;
end;

begin
  S := '*' + IntToStr(-233) + '*';
  Writeln (S);
end.

https://forumstatic.ru/files/001b/d4/a7/85076.txt


Вы здесь » Середовище програмування MADL » PascalGUI » PascalGUI.Приклади з Pascal N-IDE » Вихідні коди прикладів з Pascal N-IDE