- Pascal Tutorial
Algoritmul lui Euclid (Categoria Matematica, Autor Leonard Crestez). O prezentare a variantei extinse a algoritmului lui Euclid, care rezolva ecuatie de forma A. X + B. Y = D, unde D este cel mai mare divizor comun al lui A si B.De asemenea este prezentata o aplicatie 'interesanta': impartirea modulara. Pangkat merupakan perulangan perhitungan perkalian nilai tersebut sebanyak n kali bilangan nilai pangkat. Dengan memanfaatkan sebuah sub-rutin yang terdapat pada bahasa pemrograman pascal, kita bisa membuat program perpangkatan dengan menggunakan bahasa pemrogramna pascal. Program crayon-5e10c66548d0d034941652/ Eksekusi Setelah kita memasukan nilai basis a.
- Pascal Useful Resources
- Selected Reading
Before we study basic building blocks of the Pascal programming language, let us look a bare minimum Pascal program structure so that we can take it as a reference in upcoming chapters.
Pascal Program Structure
A Pascal program basically consists of the following parts −
- Program name
- Uses command
- Type declarations
- Constant declarations
- Variables declarations
- Functions declarations
- Procedures declarations
- Main program block
- Statements and Expressions within each block
- Comments
Every pascal program generally has a heading statement, a declaration and an execution part strictly in that order. Following format shows the basic syntax for a Pascal program −
Pascal Hello World Example
![Pascal functions list Pascal functions list](/uploads/1/2/6/2/126261675/537762685.jpg)
Following is a simple pascal code that would print the words 'Hello, World!' −
This will produce following result −
Let us look various parts of the above program −
- The first line of the program program HelloWorld; indicates the name of the program.
- The second line of the program uses crt; is a preprocessor command, which tells the compiler to include the crt unit before going to actual compilation.
- The next lines enclosed within begin and end statements are the main program block. Every block in Pascal is enclosed within a begin statement and an end statement. However, the end statement indicating the end of the main program is followed by a full stop (.) instead of semicolon (;).
- The begin statement of the main program block is where the program execution begins.
- The lines within (*...*) will be ignored by the compiler and it has been put to add a comment in the program.
- The statement writeln('Hello, World!'); uses the writeln function available in Pascal which causes the message 'Hello, World!' to be displayed on the screen.
- The statement readkey; allows the display to pause until the user presses a key. It is part of the crt unit. A unit is like a library in Pascal.
- The last statement end. ends your program.
Compile and Execute Pascal Program
- Open a text editor and add the above-mentioned code.
- Save the file as hello.pas
- Open a command prompt and go to the directory, where you saved the file.
- Type fpc hello.pas at command prompt and press enter to compile your code.
- If there are no errors in your code, the command prompt will take you to the next line and would generate hello executable file and hello.o object file.
- Now, type hello at command prompt to execute your program.
- You will be able to see 'Hello World' printed on the screen and program waits till you press any key.
Make sure that free pascal compiler fpc is in your path and that you are running it in the directory containing source file hello.pas.