תחביר
- קוד: בחר הכל
result = dividend % divisor
פרמטרים של התחביר:
dividend - המספר שמחלקים אותו
divisor - המספר שמחלקים בו
הערך המוחזר הוא השארית (reminder).
דוגמה
- קוד: בחר הכל
x = 7 % 5; // x now contains 2
x = 9 % 5; // x now contains 4
x = 5 % 5; // x now contains 0
x = 4 % 5; // x now contains 4
דוגמה של קוד
- קוד: בחר הכל
/* update one value in an array each time through a loop */
int values[10];
int i = 0;
void setup() {}
void loop()
{
values = analogRead(0);
i = (i + 1) % 10; // modulo operator rolls over variable
}
טיפ
אופרטור מודולו לא עובד על מספרים עם נקודה צפה (float, double)ראו גם:
חילוקפירוט שפת תכנות לסביבת Arduino
עמוד זה הוא תרגום של Modulo לפי רישיון Creative Commons Attribution-ShareAlike 3.0.