Question

Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...

Program : Write a complete C++ program that Input: Read a positive integer from the keyboard (user) with proper prompt text and save it to a variable. The integer have up to five digits. Processing: From the right most digit, extract every digit from the input integer using modular operator %then save the digit to a separate variable. Remove the right most digit from the integer using integer division operator /. Repeat above two steps till all digits have been extracted. Output: Print out all digits of the integer in the right-to-left or the left-to-right order with proper prompts.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {

        int n;
        cout << "Enter a positive number: ";
        cin >> n;
        while(n <= 0) {
                cout << "Invalid! Try again." << endl;        
                cout << "Enter a positive number: ";
                cin >> n;
        }

        cout << "
Printing Right to left order: " << endl;
        while(n != 0) {
                // print rightmost digit
                cout << (n % 10) << endl;

                // remove rightmost digit from number
                n = n / 10;
        }

}

Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...
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
  • Write a complete C++ program that do following. 1) Read a positive integer from the user...

    Write a complete C++ program that do following. 1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0. 2) Create a size 10 array as counters for digits 0 - 9. 3) Use a while loop for processing a) Single out the current last digit using modular 10 technique b) Increment the corresponding counter through the index derived in a). 4) At the...

  • Code in C An integer is divisible by 9 if the sum of its digits is...

    Code in C An integer is divisible by 9 if the sum of its digits is divisibleExample output: by 9. Develop a program which will call UDF: int get input(); to prompt the user for an integer and return this user input to main() Call UDF: Enter an integer: 5463 3 4 5 5463 is divisible by 9 void display int val); to display each digit of the integer starting with the rightmost digit. Your program should also determine whether...

  • using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100....

    using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100. If n is out of range then print out an error message and ask for another input. This process repeats until a valid value for n is obtained. b) Inputs two 1D arrays of doubles A and B (of size n) from the keyboard. c) Inputs an integer k (from 1 to 3) from the keyboard. d) If k = 1 then it calculates...

  • P.2. Division Write a C program to input an integer n. Then the program asks users...

    P.2. Division Write a C program to input an integer n. Then the program asks users to input n integers. Calculate the sum of all non negative integers and the division of this with every negative integer in the sequence. p3 Write a C program to print all 3-digit abc numbers, satisfying: (a+b+c)=(a.b.c). Example: 3-digit 123 number fulfills requirement as (1+2+3)=1.2.3

  • Write a complete program that declares an integer variable, reads a value from the keyboard into...

    Write a complete program thatdeclares an integer variable,reads a value from the keyboard into that variable, andwrites to standard output the square of the variable's value.

  • the user should be prompted to enter an integer and then your program will produce another...

    the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...

  • Write a complete C program with a helper function that reads an integer from the keyboard...

    Write a complete C program with a helper function that reads an integer from the keyboard and prints its factorial to the standard output

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • Write a Java class that examines a single character input from the keyboard. Follow this dialog...

    Write a Java class that examines a single character input from the keyboard. Follow this dialog to guide your coding: Type a single character and press Enter: m Digit: No Letter: Yes Lowercase: Yes Toggle case: M Note: There is no "next" method of the Scanner class to obtain input from the keyboard of data type char. It simply doesn't exist so you need a workaround. Store the end-user input into a String variable; then extract the first character using...

  • C++ please Problem 3: Write a C++ program that prompts the user to enter an integer...

    C++ please Problem 3: Write a C++ program that prompts the user to enter an integer of any length (but not more than 8- digits), the program then extracts and prints each digit in its respective column. For example, in the integer 436, 4 should be printed in the 4th column, 3 in the 3rd and 6 in the 6th column. Hint: you can use setw to solve this problem. Sample Input/Output Enter an integer of any length. 9836472 ...Printing...

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
ADVERTISEMENT