Before you systematically learn the Pascal language, let’s temporarily bypass the tedious details of grammatical rules. Through the following simple examples, you can quickly master the Pascal program. The basic composition and usage of basic statements allow beginners to directly imitate and learn to write simple programs.
[Example 1.1] Program to display "Hello World!" on the screen.
Pascal program:
Program ex11;
Begin
Writeln(‘Hello World!’);
ReadLn;
End.
With this simple sample program, I hope everyone can have a good start in programming learning. Writeln in the program is an output statement, which can instruct the computer to output corresponding content on the screen. Following the Writeln statement is a pair of parentheses, and the part enclosed in single quotes will be displayed intact.
[Example 1.2] It is known that the selling price of a bicycle is 300 yuan. Please program to calculate the total price of a bicycle?
Solution: If the total selling price is represented by m, then this problem can be divided into the following steps:
= 1 \* GB3 ①Input the number of bicycles a from the keyboard;
= 2 \* GB3 ② Use the formula m=300*a to calculate the total selling price;
= 3 \* GB3 ③ Output the calculation results.
Pascal program:
Program Ex12;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?a=’);
ReadLn(a); {Calculate total selling price}
Writeln(‘M=’, m) ; Pascal programs consist of three parts:
(1) The program header
begins with the reserved word Program, followed by a program name (such as: Exl1); its format is:
Program program name;
The program name is determined by the user Pick it yourself. Its first character must be an English letter, and subsequent characters can only be composed of letters or numbers and underscores. Operators, punctuation characters, and spaces cannot appear in the program name.