Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 6.24 Separating Digits
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- using namespace std;
- int getQuotient(int dividend, int divisor) {
- return dividend / divisor;
- }
- int getRemainder(int dividend, int divisor) {
- return dividend % divisor;
- }
- void indivDigits(int testNum) {
- for (int divisor = 10000; divisor >= 10; divisor /= 10) {
- if (testNum >= divisor) cout << getQuotient( testNum, divisor) << " ";
- testNum = getRemainder(testNum, divisor);
- }
- cout << testNum << endl << endl;
- return;
- }
- int main() {
- cout << "Enter a dividend followed by a divisor: ";
- int dividend, divisor, quotient;
- cin >> dividend >> divisor;
- quotient = getQuotient(dividend, divisor);
- cout << "quotient is: " << quotient << endl;
- cout << "The remainder, after division, is: " << getRemainder( dividend, divisor) << endl << endl;
- while (true) {
- int testNum = 0;
- cout << "Enter an integer from 1 to 32767 (inclusive) or enter 0 to end: ";
- cin >> testNum;
- if (testNum == 0) break;
- cout << "Individual digits are as follows: ";
- indivDigits(testNum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment