answersLogoWhite

0

What is the modulus used for in programming?

Updated: 8/11/2023
User Avatar

Wolfaaron

Lvl 1
12y ago

Best Answer

The modulus operator (%) is used to return the partial value that remains when the first operand is divided by the second. If you recall learning long division, most systems start with a "remainder" that is a whole number rather than a decimal point. The modulus returns this value.

For example 10 % 3 means "Take the number ten and find the nearest full division of 3, which in this case would be 9 (3 * 3). Then take that number, and subtract it from the original number, 10."

You see modulus used a lot to determine whether a number is even or odd. This for loop (written in PHP) will produce HTML table rows, with the even rows give the class of "even."

<?php

$rowset = '';

$set = array ( 'a', 'b', 'c', 'd', 'e', 'f', 'g' );

for ( $i = 1; $i <= count ( $set ); $i++ )

{

if ( $i % 2 == 0 0

{

$class = 'class="even"';

}else{

$class = '';

}

$rowset .= '<tr '.$class.'><td>'.$set[$i].'</td></tr>';

}

echo $rowset;

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

In short: Modulus of a number means the positive value of that number weather it is positive or negative.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the modulus used for in programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

In a programming language what is the difference between division and modulus?

Division provides Quotient whereas Modulus provides Remainder.


Why is m used in the slope formula?

what we now call just the "slope" was once called the "modulus of slope", the word "modulus" being used in its sense of "number used to measure" (as in "Young's modulus").


What operator performs division but instead of returning the quotient it returns the remainder?

Modulus page 46 Programming Logic and Design by Tony Gladdis


What is the types of modulus of elasticity?

1. Young's modulus of elasticity, E, also called elastic modulus in tension 2. Flexural modulus, usually the same as the elastic modulus for uniform isotropic materials 3. Shear modulus, also known as modulus of rigidity, G ; G = E/2/(1 + u) for isotropic materials, where u = poisson ratio 4. Dynamic modulus 5. Storage modulus 6. Bulk modulus The first three are most commonly used; the last three are for more specialized use


What graphs are used in frequency distribution?

graph of modulus


Where could a person buy a Modulus guitar?

Modulus Guitars was founded by Geoff Gould in the 1970's. Modulus guitars can be difficult to find. One may be able to find a Modulus guitar on the online website Musician's Friend. It may also be possible to find used Modulus guitars for sale on a website such as eBay or Kijiji.


What are the different types of modulus elasticity?

there are different types of modulus it depends on what types of stress is acting on the material if its direct stress then then there is modulus of elasticity,if tis shear stress then its modulus of rigidity and when its volumetric stress it is bulk modulus and so on


The modulus operator can be used only with integer operands?

True


Is tensile modulus the same as young's modulus?

Yes, indeed. Sometimes tensile modulus is different from flexural modulus, especially for composites. But tensile modulus and elastic modulus and Young's modulus are equivalent terms.


Definition of young modulus?

The young modulus young modulus(E) = stress/strain stress = force/area strain = extension(total length)/original length It is this property that determines how much a bar will sag under its own weight or under a loading when used as a beam within its limit of proportionality


What is the relation between elastic modulus and tensile modulus?

The elastic modulus, also called Young's modulus, is identical to the tensile modulus. It relates stress to strain when loaded in tension.


Is young's modulus storage modulus?

The Young modulus and storage modulus measure two different things and use different formulas. A storage modulus measures the stored energy in a vibrating elastic material. The Young modulus measures the stress to in still elastic, and it is an elastic modulus.