MATHLAB PROGRAM Your Task Your task is to implement a functi

MATHLAB PROGRAM
Your Task
Your task is to implement a function with the following signature.
  1. Argument x is a nonnegative integer.
  2. Argument y is a positive integer.
  3. Outputs q and r satisfy: x = q*y + rwith 0 <= r < y.
Here is the usual implementation for this function in Matlab: one using floating point numbers and floor:
However, this is how your function must be implemented:
  1. You must use repeated subtraction.
  2. You must use either a loop or recursion.
  3. You must not use any other functions or operations, including rem, mod, floor or /.
MATHLAB PROGRAM
Your Task
Your task is to implement a function with the following signature.
  1. Argument x is a nonnegative integer.
  2. Argument y is a positive integer.
  3. Outputs q and r satisfy: x = q*y + rwith 0 <= r < y.
Here is the usual implementation for this function in Matlab: one using floating point numbers and floor:
However, this is how your function must be implemented:
  1. You must use repeated subtraction.
  2. You must use either a loop or recursion.
  3. You must not use any other functions or operations, including rem, mod, floor or /.
Your Task
Your task is to implement a function with the following signature.
  1. Argument x is a nonnegative integer.
  2. Argument y is a positive integer.
  3. Outputs q and r satisfy: x = q*y + rwith 0 <= r < y.
Here is the usual implementation for this function in Matlab: one using floating point numbers and floor:
However, this is how your function must be implemented:
  1. You must use repeated subtraction.
  2. You must use either a loop or recursion.
  3. You must not use any other functions or operations, including rem, mod, floor or /.
Your task is to implement a function with the following signature.
Here is the usual implementation for this function in Matlab: one using floating point numbers and floor:
However, this is how your function must be implemented:

Solution

function [q, r] = divmod(x, y)
if x<y
    error(\'Dividend should be greater than divisor\')  
end

if y==0
    error(\'Division by zero is not allowed\')  
end

count=0;%Initialize count
a=0;%Initialize a

while(x>=y&&x>=0)
    for i=y
        x=x-i;%Repeated subtraction
        count=count+1;
    end
end

q=count;%Assign quotient
r=x;%Assign remainder
end

 MATHLAB PROGRAM Your Task Your task is to implement a function with the following signature. Argument x is a nonnegative integer. Argument y is a positive inte
 MATHLAB PROGRAM Your Task Your task is to implement a function with the following signature. Argument x is a nonnegative integer. Argument y is a positive inte

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site