Question

Write a MATLABT code that divides an integer n by an integer m using successive addition....

Write a MATLABT code that divides an integer n by an integer m using successive addition. Use a while loop to keep adding m until n is reached and exceeded. Return the quotient q and the remainder r:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SCREENSHOT

OUTPUT

CODE TO COPY

function [q, r] = div(n, m)
q = 0;
while n >= m
q += 1;
n -= m;
end
r = n;
end

[one, two] = div(30, 7)

% Hit the thumbs up if you are fine with the answer. Happy Learning!

Add a comment
Know the answer?
Add Answer to:
Write a MATLABT code that divides an integer n by an integer m using successive addition....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. [10 marks] Modular Arithmetic. The Quotient-Remainder theorem states that given any integer n and a positive integer...

    1. [10 marks] Modular Arithmetic. The Quotient-Remainder theorem states that given any integer n and a positive integer d there exist unique integers q and r such that n = dq + r and 0 r< d. We define the mod function as follows: (, r r>n = qd+r^0<r< d) Vn,d E Z d0 Z n mod d That is, n mod d is the remainder of n after division by d (a) Translate the following statement into predicate logic:...

  • Introduction to embedded systems Microprocessors 4.10 For integer division M/D, D neq 0 and M being...

    Introduction to embedded systems Microprocessors 4.10 For integer division M/D, D neq 0 and M being an n-bit word, yielding a quotient Q and remainder R. one algorithm that mimics long division is the following: Step 1: Initialize Q = 0, R = 0 Step 2: FOR j = n - 1 to 0 DO 2.1 R 2R + M(j) 2.2 IF R>=D THEN a. R R - D b. Q(j) = M(j) FNDIF In this algorithm, M(j) means the...

  • Write code in Java. In this step, functions and methods are synonymous. You may assume that...

    Write code in Java. In this step, functions and methods are synonymous. You may assume that strings only contain uppercase letters A through Z. 1. Write a function as follows: o Receive a string as a parameter. o Count the length of the string Count the occurrences of each distinguishable symbol in the string (use an array or map/dictionary). o Divide the factorial of the length by the product of the factorials of the occurrences. o Return the quotient as...

  • Part A Write a Java program that reads an integer n from the keyboard and loops...

    Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.   Will give thumbs up...

  • Integer Math Create an application that uses random integers to test the user’s knowledge of arithmetic....

    Integer Math Create an application that uses random integers to test the user’s knowledge of arithmetic. Let the user choose from addition, subtraction, multiplication, and division. The integers used in the problems should range from 20 to 120. When giving feedback, use color to differentiate between a correct answer response, versus an incorrect answer response. Also check for non-integer input. Preparing division problems requires special consideration because the quotient must be an integer. Therefore, you can use a loop to...

  • 4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 4 (integer...

    4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 4 (integer division) until reaching 2. Follow each number by a space. Example output for userNum = 160: 40 10 2 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • Integer Math- Console based---uses Windows Form in Visual Basic   Create an application that uses random integers...

    Integer Math- Console based---uses Windows Form in Visual Basic   Create an application that uses random integers to test the user’s knowledge of arithmetic. Let the user choose from addition, subtraction, multiplication, and division. The integers used in the problems should range from 20 to 120. When giving feedback, use color to differentiate between a correct answer response, versus an incorrect answer response. Also check for non-integer input. Preparing division problems requires special consideration because the quotient must be an integer....

  • 12. 10 points) Use pseudocode to write out algorithms for the following problems. (a) Assume n is any integer with...

    12. 10 points) Use pseudocode to write out algorithms for the following problems. (a) Assume n is any integer with n 2 7. Write out an algorithm SumofCertainIntenger in pseudocode that uses n as input variable. Use a "for" loop to compute the sum (Gk +4) (b) Assume m is any integer with m 2 5. Write out an algorithm ProductOfCertainInte- gers in pseudocode that uses m as input variable. Use a "while" loop to compute the product IT (é+4)....

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT