MedVision ad

Checking if one value is divisable by another (1 Viewer)

Silverwolf

New Member
Joined
May 10, 2004
Messages
7
Location
Tea Gardens NSW
Everything else for my major is finished, except for this last little bit of one of my modules that I simply can't figure out :S. I need the module to check wether or not Num01 is divisable by Num02.

I spent the last 2 school weeks fiddling around with various methods and nothing seemed to work (don't bother asking what I tried, can't remember after 2 weeks of holidays). The module will do everything it's supposed to do after that (manually chucked in some data), but I can't get it to make this check.

plz help!!
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
The Mod operator returns the remainder when two numbers are divided. So if Num01 is divisible by Num02. Num01 Mod Num02 = 0

eg.
Code:
' in some procedure
  MsgBox 4 Mod 3    ' gives 1
  MsgBox 4 Mod 2    ' gives 0
 

Mumma

Member
Joined
May 19, 2004
Messages
586
Location
Sydney
Gender
Male
HSC
2006
Here is a recursive function written in python/pseudocode that will return the greast common divisor, helpful sometimes.

Code:
[COLOR=DarkOrange]def[/COLOR] [COLOR=RoyalBlue]gcd[/COLOR](m,n):
    [COLOR=DarkOrange]if[/COLOR] m % n == 0: [COLOR=DarkOrange]return[/COLOR] n
    [COLOR=DarkOrange]return[/COLOR] GCD(n,m%n)

[B]BEGIN SUBPROGRAM[/B] [U]GCD(m,n)[/U]
    [B]IF[/B] remainder of m/n = 0 [B]THEN[/B]
        return n
    [B]ELSE[/B]
        return [U]GCD(n,remainder of m/n)[/U]
    [B]END IF[/B]
[B]END SUBPROGRAM [/B]

Edit: damn, i didnt realise this thread was so old. this place is dead.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top