# Divisibility rule

## Recommended Posts

Hello to all,

for a program that check newspaper pages i must control if number of given fies is divisible by 4

Find some rules on Wikipedia and find here some rules, also for number 4

`The last two digits divisible by 4.     40832: 32 is divisible by 4`

but i've not idea to code this simple rule,

Any math guy can help me ?

thank you,

m.

##### Share on other sites

Hello to all,

for a program that check newspaper pages i must control if number of given fies is divisible by 4

Find some rules on Wikipedia and find here some rules, also for number 4

`The last two digits divisible by 4.     40832: 32 is divisible by 4`

but i've not idea to code this simple rule,

Any math guy can help me ?

thank you,

m.

Hi,

```\$number = 40832
; Get the two numbers from the right and perform a modulus operation
\$var = Mod (StringRight (\$number, 2), 4) ;see help for function Mod
If \$var = 0 Then
MsgBox (0,"",\$number & " is divisible by 4")
Else
MsgBox (0,"",\$number & " is not divisible by 4")
EndIf```

or

```\$number = 40832
If Mod (StringRight (\$number, 2), 4) = 0 Then
MsgBox (0,"",\$number & " is divisible by 4")
Else
MsgBox (0,"",\$number & " is not divisible by 4")
EndIf```

;-))

Stefan

Edited by 99ojo

##### Share on other sites

Just check the whole number, your Computer should be fast enough

```\$Num = InputBox("Insert a number", "Type a page number to check")
\$Num = Number(\$Num) ; make number from string

\$Mod = Mod(\$Num, 4) ; calculate remainder
If \$Mod = 0 Then
MsgBox(64, 'OK', "Number of pages (" & \$Num & ") is divisible by 4. Page count OK")
Else
MsgBox(16, 'ERROR', "Number of pages (" & \$Num & ") is NOT divisible vby 4" & @CRLF & _
"You have to REMOVE " & \$Mod & " pages" & @CRLF & _
"OR ADD " & (4-\$Mod) & " more page(s)." )
EndIf```
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

## Create an account

Register a new account

×

• Wiki

• Back

• Git