2. Modular arithmetic
Write a function that returns the result of any integer modulo of n (i.e., reduce theinteger modulo n). Note that the C++ operator % can be used, but it returns a negativevalue, for example, -1 % 3 yields -1, so we need to do something adjustment (recallthat -1 mod 3 = 2 because -1= (-1)×3+2). Therefore, we will use the mod() functionfrom this step to implement the later encode() and decode() functions.
/* precondition: n is greater than 1,a can be negativepostcondition: 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++
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here