Forum > Beginners

Problem with easy program

(1/1)

godik:
I am pretty low skill at lazarus can you please tell me why is this program not working ? I started it through the Simple Program.

var i,c:word;

begin
  readln(c);
  for i:=1 to c do

  if(c mod i =0) then write (i,',');
end. 

Handoko:
What was the input did you provide? And what was the result you're expecting?

I tried to provide 5 for the input, the result is 1 and 5. That's correct because:
5 mod 1 = 0
5 mod 2 = 1
5 mod 3 = 2
5 mod 4 = 1
5 mod 5 = 0

Read more about mod:
http://wiki.freepascal.org/Mod

godik:
When I start the program and I type some number it is just shutting down the program.

Handoko:
I cannot reproduce your issue. Tested on Lazarus 1.8.4.

You may need to attach the source code and send it the forum so we can inspect it for you.

-edit-
Maybe you need to put this below before the end.:
  ReadLn;

godik:
That is it thank you very much  :D

Navigation

[0] Message Index

Go to full version