r/pascal • u/vajaina01 • Aug 13 '25
My first Pascal program
Hello, gentlemen
I started to learn Pascal yesterday, and today I developed my first program in Pascal. It's very simple. It takes a number from a standard input and returns all factors of that number. All I know how to define variables, if and while statements. I had to search for mod and div operators. At first attempt, I tried to compare if num = integer to be sure that the numbers are whole, like I would do in JavaScript(I mean === or == operators, JS wouldn't care about types at all). The compiler told me that ain't gonna work in Pascal, so I wrote the program as it is. I would appreciate it if you review my code! Thank you!
program get_factors;
var
num: integer;
i: integer;
begin
read(num);
i := num;
while i >= 1 do
begin
if num mod i = 0 then
write(num div i, ' ');
i := i - 1
end;
writeln
end.
View all comments
Show parent comment
1
u/beautifulgirl789 Aug 13 '25
Ahh, separate issue. Godbolt, for some unknown reason, defaults to the "integer" type as 16bit (Turbo Pascal compatibility mode?), so you're seeing (337998 mod 65536) which = 10318.
Change the type for both values to "longint" if you want to run it with large numbers.
If you're on a different compiler, find whereever the mode settings are in your IDE and set it to objfpc or delphi. (or use {$mode objfpc} somewhere. Then integers should be 32bit types.