ماشینحساب باقیمانده (a mod n)
این ماشینحساب a mod n، یعنی باقیماندهٔ تقسیم a بر n، را برای هر عدد صحیحی، از جمله منفی، پیدا میکند. خارجقسمت، تفریق و تفاوت پاسخ ریاضی با عملگر % در برخی زبانهای برنامهنویسی را نشان میدهد.
نتیجه
مقادیر را وارد کنید و برای دیدن نتیجه «محاسبه» را بزنید.
فرمول
Divide, round down to a whole number, multiply back and subtract. For n > 0 the answer is between 0 and n − 1.
نحوه استفاده از این ماشینحساب
- Enter the number a and the modulus n (whole numbers; n cannot be 0).
- Press Calculate to see a mod n, the quotient and each step.
مثالهای حلشده
17 mod 5
17 ÷ 5 = 3.4, which rounds down to 3.
17 − 5 × 3 = 2, so 17 mod 5 = 2.
−17 mod 5 (a negative number)
−17 ÷ 5 = −3.4, which rounds down to −4.
−17 − 5 × (−4) = 3, so −17 mod 5 = 3. (The % operator in C or JavaScript gives −2.)
100 mod 7
100 ÷ 7 = 14.28…, so the quotient is 14.
100 − 7 × 14 = 2.
اشتباههای رایج
- Giving the quotient instead of the remainder: 17 mod 5 is 2, not 3.
- Rounding −3.4 to −3 instead of down to −4 for negative numbers.
- Expecting the same answer from % in every programming language; they differ for negatives.
پرسشهای متداول
What does mod mean in math?
a mod n is the remainder when a is divided by n. For example 17 mod 5 = 2, because 17 = 3 × 5 + 2.
How do you calculate mod of a negative number?
Divide and round down (towards negative infinity), then subtract. −17 mod 5: −17 ÷ 5 = −3.4 → −4, and −17 − 5 × (−4) = 3.
Where is modulo used?
Clock arithmetic (14:00 is 2 pm because 14 mod 12 = 2), checking whether a number is even (n mod 2), check digits, and programming.