Can pencil code perform a integer division like Java ?

24 views
Skip to first unread message

frees...@gmail.com

unread,
Sep 26, 2019, 11:08:52 PM9/26/19
to Pencil Code
Hi,
In Java, if 1 / 5 will get 0 as its quotient and 1 as its remainder.
Can Javascript setting in pencil code perform the integer division like Java ?

Thanks,

pet...@gmail.com

unread,
Dec 10, 2019, 11:55:26 AM12/10/19
to Pencil Code
Yes:  use the // operator to do integer division.  Alternatively, do regular division with /, and truncate the decimal using the floor function.  A useful related operator is the modulus (or mod) operator, %, which give the remainder:


dividend = 23
divisor = 7

quotient = floor(dividend/divisor)
remainder = dividend%divisor
#equivalently, but you'll see a red x off to the 
# left in the pencil code editor:  
quotient = dividend//divisor
  
write "what is " + dividend + "/" + divisor + " ?"
write "The quotient is " + quotient

write "And the remainder is " + remainder
Reply all
Reply to author
Forward
0 new messages