List of all available Websheets
Viewing cpp/while/div-without-div by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>To divide two integers in C++, we can write <tt>a/b</tt>.</p> <p>Now suppose the <tt>/</tt> key was broken on your keyboard, we could compute the answer another way. We could count how many times we have to subtract b from a provided the result is still non-negative.</p> <p>Write a program that first asks the user (no prompt needed) for <tt>a</tt> and <tt>b</tt> and then computes the integer quotient and remainder of <tt>a/b</tt> without using <tt>/</tt>.</p> <p>You should output the quotient first and the remainder second. For example, given the input: <tt>7 3</tt> you should output <tt>2 1</tt>.</p> <p><strong>You may use whatever loop you deem appropriate</strong>, though we'd like to suggest using a for loop as practice.</p> |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/for/polydeg (author: redekopp@usc.edu) Copied from problem cpp/for/blastoff (author: redekopp@usc.edu) Copied from problem cpp/while/blastoff (author: redekopp@usc.edu) Copied from problem cpp/while/goldilocks (author: redekopp@usc.edu) Copied from problem cpp/while/sum50 (author: redekopp@usc.edu) Copied from problem cpp/conditionals/rps (author: redekopp@usc.edu) Copied from problem cpp/conditionals/taxbrackets (author: redekopp@usc.edu) Copied from problem cpp/conditionals/nestedec (author: redekopp@usc.edu) Copied from problem cpp/conditionals/extracredit (author: redekopp@usc.edu) Copied from problem cpp/control/flag (author: daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; int main() { int a, b; \[ cin >> a >> b; int q = 0; for( ; a >= b; a -= b){ q++; } cout << q << " " << a << endl; ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "7 3", "args": ""}, {"stdin": "100 4", "args": ""}, {"stdin": "6 7", "args": ""}, {"stdin": "2001 2", "args": ""} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.