Jump to content

Multiples of Integers


Jarin

Recommended Posts

Well, considering I'm not very math savvy, I need a bit of help. I'm trying to determine whether one integer is evenly divisible into another integer, IE is 1033343 a multiple of 3, is 105 a multiple of 5, etc. How would one go about determining this in a memory-conservative manner?

Thanks in advance.
Link to comment
Share on other sites

[!--quoteo(post=364686:date=Apr 14 2006, 02:29 PM:name=Jarin)--][div class=\'quotetop\']QUOTE(Jarin @ Apr 14 2006, 02:29 PM) [snapback]364686[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Well, considering I'm not very math savvy, I need a bit of help. I'm trying to determine whether one integer is evenly divisible into another integer, IE is 1033343 a multiple of 3, is 105 a multiple of 5, etc. How would one go about determining this in a memory-conservative manner?

Thanks in advance.
[/quote]
use the '%' operator which gives you the remainder of a division. e.g $i = 5 % 5; #$i=0;
Link to comment
Share on other sites

You could probably just use the Modulus operator. This basically divides 2 numbers and tells you what the remainder is. So you could test and see if it's equal to 0, and if so, then you know that one number is a multiple of another. Here's an example using the numbers from your example:

[code]
$a = 1033343;
$b = 3;
$result = $a % $b;
if ($result == 0)
       echo 'the two numbers are evenly divisible';
else
       echo 'the two numbers are not evenly divisible';
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.