The demand for the profession of a programmer is growing every year. At the moment, about a dozen languages of different levels are actively used to write codes. In order to make the process of teaching computer programming more efficient, senior and 1-2 year students are taught to create their first native applications in Pascal. This article is devoted to operations of div and mod and other calculations in its environment.
A few words about Pascal
«» 1968-1969 , « ». "-68". , 1970- , , .
«» , . .
. , . , :
24:6=4;
100:3=33
55:6=9;
.
.
, , , , .
a b, q.
. . .
div «»
— div. Pascal , , :
q:= a div b.
, , a=50, b=9, q:= 50 div 9. q 5.
div «» mod. , , , .
, , , , . .
r = a – b x q.
mod «»
Pascal . mod.
:
r = a mod b.
, , a=50, b=9, r:= 50 mod 9. r 4.
(r) . .
mod , . . . , , mod 0.
"" :
if a mod b = 0 then write (a, '', b).
, , , a=4 b=2 «4 2».
, mod . r = a mod 10. , r = 37 mod 10 7.
trunc
, , div "". trunc, . . «» . . a=51, b=9. q:= 51 div 9 q:= 5, . trunc, q:= trunc (51/9) q:= 5, . . .
1
, div mod "" . . :
- , , 10, mod;
- , , mod div "".
«». :
program Sum_2; ( )
var Number,Number1,Number2,Sum: integer; ( , )
begin ( )
write('Input Two-digit number'); ( "Input Two-digit number")
read(Number); ( )
Number1 := Number div 10; ( )
Number2 := Number mod 10; ( )
sum := Number1 + Number2; ( )
write(Sum); ( )
end.
25 7, , , 37 — 9.
2
, 3- .
— . 1-. div "" 100. , . , , 10 div, 10 mod.
:
program Sum_3; ( )
var Number3,Sum: integer; ( , )
begin ( )
write (' Input Tree-digit number '); ( «Input Tree-digit number»)
read (Number3); ( )
Sum := Number3 div 100 + Number3 mod 10 + Number3 div 10 mod 10; ( )
write ('Sum); ( )
end.
, . div "", mod, , .
(. . 2- ) . , . *, /, mod div , + –. , , — + –.
, div "". , mod, , , .