% (Modulo)

From Microduino Wiki
Revision as of 06:46, 10 August 2016 by Fengfeng (talk) (Created page with "*'''%(Modulo)''' *'''Description''' The remainder of in integer divided by another number is called modulus, which serves to keep a variable in a specified scope (such...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • %(Modulo)
  • Description

The remainder of in integer divided by another number is called modulus, which serves to keep a variable in a specified scope (such as the size of the array).

  • Syntax

Result=Dividend%divisor

Parameters Dividend:A number which is to be divided

Divisor:A number used to divide the other number Return

Remainder(modulus)

  • Example

X = 7%5; // X is 2
X = 9% 5;// X is 4
X = 5% 5;// X is 0
X = 4%5; // X is 4

/*Calculate the modulus of 1 to 10 through the circulation. */


int values[10];
int i = 0;
 
void setup () {
}
 
void loop()
{
  values [i] = analogRead(0);
  i =(i + 1)%10; //modulo operation 
}
  • Note

The modulo operator doesn’t work to floating-point numbers.

[Return to Arduino Syntax Manual]