Modulo Expression
The modulo operator (%) in Lipi is used to calculate the remainder of a division operation.
Syntax
expression % expressionBasic Usage
The modulo operator returns the remainder when the first operand is divided by the second operand:
purna a;
purna b;
purna result;
a = 10;
b = 3;
result = a % b; :) result = 1
bhana("10 % 3 = ");
bhana(result);Checking for Even/Odd Numbers
A common use of the modulo operator is to check if a number is even or odd:
purna num;
num = 7;
yadi(num % 2 == 0) {
bhana("The number is even.");
}anyatha {
bhana("The number is odd.");
}Modulo in Loops
The modulo operator is often used in loops to perform actions at specific intervals:
purna i;
lagi(i = 1; i <= 10; i = i + 1;) {
yadi(i % 3 == 0) {
bhana("Divisible by 3: ");
bhana(i);
}
}Next Steps
Now that you understand the modulo operator in Lipi, you can learn more about: