Programs in pascal examples




















In the following program, the computer must prompt the user to enter a number, then the latter is added to the second number input by the user. Now we must take a look at the program. A program in Pascal starts with the reserved word ' Program ' although it is not explicitly required and ends with ' End ', following a full stop this is required though.

A full-stop is never used within the program, except when dealing with records later topics and at the end of the program as seen in the example above. The ' Var ' keyword is used to introduce variables in a program to be used later on as temporary data storage elements.

As you can see in the example above, these variables are declared as Integers. The data type 'Integer' means any whole number, i. The Pascal Integer data type ranges from to So values which are not within the specified range cannot be stored by an integer type. There are other types which are wider in range, but for now the integer type is enough to hold up our values.

The variables 'Num1', 'Num2' and 'Sum' are identifiers which are not reserved words, but can be used as our variables in the program to store data in them. They could be changed more than once. Moreover, we could have used 'number1', 'number2' and 'totalsum' note that there must be no spaces within the variables , instead of 'Num1', 'Num2' and 'Sum', respectively. After declaring all the variables which are required to be used later in the program, the main program always starts with the reserved word ' Begin '.

Without this word, the compiler will display a diagnostic error message. In the program above, both of the two types of 'write' are used. These are ' write ' and ' writeln '. Both has the same function, except that the ' write ' function, does not proceed to the following line when writing a statement.

If you run this program, you will notice the difference between them. When using these two terms, any message that will be typed in between the brackets and the inverted commas ' ' ' ', is displayed on the screen. However, if a variable is used instead of a message, without using the inverted commas, the CPU will display the stored variable in the memory, on the screen. In line 9, the CPU will not display 'Sum' on the screen, but the stored number in the memory. Logical Boolean data type: boolean Numbers - Types for storing numbers.

Integers - Types for storing integers. Unsigned - Types for storing unsigned integers. Thanks to this we can overwrite automatic conversion. Explicit - By using an explicit conversion, you can specify exactly what type you want to work with. To 8-bit integer: shortint To 8-bit unsigned integer: byte To bit integer: integer To bit unsigned integer: word To bit integer: longint To bit real number: single To bit real number: double To boolean: Boolean Variables - Variable is used for storing the data.

Variable declaration Variable use. Statements Statements are one step in the program. Expressions Expressions are such a part of the program that performs some operation and then returns t Operators perform an operation between the operands, this operation can be mathematical, logical, or bitwise. The pay computations assign their result to variable Pay, which is then displayed. Note that the second assignment statement to Pay:. This is because of the Real constant 1. To store this Real value in an integer variable it is necessary to convert it using the ROUND standard function, which we just saw in the Convert program above.

Pascal Programming Interview Questions. Pascal Programming Practice Tests. IT Skills. Management Skills. Communication Skills. Business Skills. Digital Marketing Skills. Human Resources Skills. Health Care Skills. Finance Skills. All Courses. All Practice Tests. Pascal Programming Tutorial. Job Recommendation Latest. Jobs in Meghalaya Jobs in Shillong. View All Locations. How to design your resume?

Have you ever lie on your resume? Read This Tips for writing resume in slowdown What do employers look for in a resume?



0コメント

  • 1000 / 1000