2. Modular arithmetic Write a function that returns the result of any integer modulo of n (i.e., reduce the integer modulo n). Note that the C++ operator % can be used, but it returns a negative...


2. Modular arithmetic


Write a function that returns the result of any integer modulo of n (i.e., reduce the
integer modulo n). Note that the C++ operator % can be used, but it returns a negative
value, for example, -1 % 3 yields -1, so we need to do something adjustment (recall
that -1 mod 3 = 2 because -1= (-1)×3+2). Therefore, we will use the mod() function
from this step to implement the later encode() and decode() functions.


/* precondition: n is greater than 1,a can be negative
postcondition: return a mod n (as defined in class)
a mod n = r if and only if a = nk+r, 0 =< r="">< n="" (note="">
r needs to be non-negative).
*/
int mod (int a, int n);



-Please write in c++



Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here