answersLogoWhite

0

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

13y ago

What else can I help you with?

Related Questions

What are some common applications of the modulus operator in programming languages?

The modulus operator in programming languages is commonly used for tasks such as determining if a number is even or odd, calculating remainders in division operations, implementing cyclic patterns, and indexing elements in arrays or lists.


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

Division provides Quotient whereas Modulus provides Remainder.


The modulus operator can be used only with integer operands?

Yes, the modulus operator (%) is used to find the remainder of a division operation between two integers. It can only be used with integer operands in programming languages. If you try to use it with non-integer operands, you may encounter errors or unexpected results.


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 is the difference between Young's modulus and elastic modulus?

Young's modulus and elastic modulus are often used interchangeably, but there is a subtle difference between the two. Young's modulus specifically refers to the ratio of stress to strain in the elastic region of a material's stress-strain curve, while elastic modulus is a more general term that can refer to any modulus of elasticity that describes a material's ability to deform elastically under stress.


What graphs are used in frequency distribution?

graph of modulus


What is the difference between tensile modulus and Young's modulus, and how do they compare in terms of measuring the stiffness of a material?

Tensile modulus and Young's modulus both measure a material's stiffness, but they are calculated differently. Young's modulus specifically measures a material's resistance to deformation under tension, while tensile modulus measures its stiffness when pulled in tension. In general, Young's modulus is more commonly used and provides a more accurate measure of a material's stiffness compared to tensile modulus.


Is Young's Modulus the same as Modulus of Elasticity?

Yes, Young's Modulus is the same as Modulus of Elasticity.


Is the modulus of elasticity the same as Young's modulus?

Yes, the modulus of elasticity is the same as Young's modulus.


What is the difference between elastic modulus and Young's modulus, and how do they relate to each other in terms of material properties?

Elastic modulus and Young's modulus both measure a material's stiffness, but they are not the same. Young's modulus specifically measures a material's resistance to deformation under tension or compression, while elastic modulus is a more general term that can refer to various types of deformation. In terms of material properties, Young's modulus is a specific type of elastic modulus that is commonly used to characterize a material's stiffness.