Last Updated:

Basic operations and procedures in Pascal

procedures in Pascal

In this article, we will talk about various basic mathematical operations in the pascal language. We'll look at integer division, normal division, integer division with residue highlighting.

Division

Normal division

The usual division by pascal occurs using the slash operator - "/". This operator can be used in programs, problem solvers, loops and algorithms. Pascal, like many other languages, has this simple operator.

 

Integer division

 

Integer division occurs according to a different principle. For integer division, use the div operator.

It works as follows: a number is divided by a number, and as a result of division, the remainder is removed.
If you divide the number 5 by the number 2, and use the div-division operator, the result is 2 instead of 2.5, because the statement removes this residue.

Integer division with residue selection

Integer division with the allocation of the remainder occurs according to a different principle. For an integer division with a residual selection, the mod operator is used.

It works as follows - the number is divided by a number, but only the remainder of the division is recorded in the response.

If you divide the number 5 by the number 2, and use the mod division operator, the result is 1 instead of 2 (1 in the remainder), since the operator leaves only the number in the remainder.

Subtraction

Normal subtraction

Subtraction on the pascal occurs using the minus operator - "-". It can be used with variables of the real type, as well as the integer type. There is nothing remarkable in it, such a subtraction operation is in all programming languages, and pascal is no exception.

Dec Procedure

Procedure Dec: This procedure subtracts a specific value from a specific variable.
It is written as follows:

some variable:= Dec(variable name, value to be subtracted)

Example:

A:=Dec(B, 10) //One dozen will be subtracted from the number B

By the way, if you do not write the value, and this is not considered an error, then one unit will be subtracted from the number.

Addition

Normal addition

Addition on the pascal occurs using the plus - "+" operator. This operator can be used in programs, problem solvers, loops and algorithms. There is nothing remarkable in it, such an addition operation is in all programming languages, and pascal is no exception.

Procedure Inc

Procedure Inc. This procedure adds a specific value to a specific variable. It is written as follows:

some variable:= Inc(variable name, value to be added)

Example:

A:=Dec(B, 10) //One dozen will be added to number B

By the way, if you do not write the value, and this is not considered an error, then one unit will be added to the number.

Total

The Pascal language has all the basic mathematical operations that are needed to write programs.