Pascal · lesson 4 of 30 · First stepsCount with numbers
div and mod work on whole numbers, / gives a fraction. Int64 holds large sizes. In the default mode of fpc the largest Integer is 32767.
04-numbers.pas Download 04-numbers.pas
program Numbers;
const
KiB = 1024;
var
Bytes: Int64;
begin
WriteLn('17 + 5 = ', 17 + 5);
WriteLn('17 / 5 = ', 17 / 5:0:2);
WriteLn('17 div 5 = ', 17 div 5);
WriteLn('17 mod 5 = ', 17 mod 5);
WriteLn('rounded: ', Round(3.7), ', cut: ', Trunc(3.7));
Bytes := 8001563222016;
WriteLn(Bytes, ' bytes');
WriteLn(Bytes / KiB / KiB / KiB:0:1, ' GiB');
WriteLn('largest Integer: ', High(Integer));
end.
Terminal
$ ./04-numbers
17 + 5 = 22
17 / 5 = 3.40
17 div 5 = 3
17 mod 5 = 2
rounded: 4, cut: 3
8001563222016 bytes
7452.0 GiB
largest Integer: 32767Exercise
Add {$mode objfpc} and look at the largest Integer again.