Question

Write a program that prints to cout, separated by a space, the digits of any positive...

Write a program that prints to cout, separated by a space, the digits of any positive three digit integer. You will need one variable, named, for example, value, for the number (int value) to be broken down into its digits. You might also need other variables to store the digits as you get them. This is c++. Cant use loops, if else statements etc.

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

int main() {
    int value;
    cout << "Enter a 3-digit number: ";
    cin >> value;
    if(value < 10) {
        cout << value << endl;
    } else if(value < 100) {
        cout << value/10 << " " << value%10 << endl;
    } else {
        cout << value/100 << " " << (value%100)/10 << " " << value%10 << endl;
    }
    return 0;
}

Enter a 3-digit number: 3 4 7 347 Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Write a program that prints to cout, separated by a space, the digits of any positive...
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
  • Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1...

    Output Enter base: 2 supply a list of digits separated by space: 1 0 0 1 The value for Base = 2 and digits = 1 0 0 1 is 9 Enter base: 16 supply a list of digits separated by space: 99 All digits must be in the range [0,n) Enter base: 16 supply a list of digits separated by space: 9 9 The value for Base = 16 and digits = 9 9 is 153 Enter base: 2...

  • Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers)....

    Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers). Prompts the user for a starting number: say 'x' Prompts the user for an ending number: say 'y' Prints out the multiplication table of 'x' up to the number 'y' Sample outputs include:    SPECIFIC REQUIREMENTS You must use the following method to load the array: public static void loadArray(int table[ ][ ], int x, int y) You must use the following method to...

  • Write a C program which calculates how many digits a number has and prints each digit...

    Write a C program which calculates how many digits a number has and prints each digit in reserve order with space in between(no space after the last digit). The number > 0 and has no more than 5 digits. (optional] It is better to write two functions. One is designed for printing number in reverse order and the other is for counting the number of digits. Given that the value of number (which is an int variable) is 12345, the...

  • Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1,...

    Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1, e.g.           73 95 61 21 90 85 14 78 -1 The values should be stored in an array.   The program then prints the values in reverse order as well as the average (to one decimal place). For example, Please enter the integers: 73 95 61 21 90 85 14 78 -1 The values in reverse order are         78   14   85   90   21...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....

    (c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately....

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive...

    Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y' SPECIFIC REQUIREMENTS 1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to...

  • C++ Write a program that reads three positive integers (> 0) from the command line (one...

    C++ Write a program that reads three positive integers (> 0) from the command line (one at a time), then computes and prints the smallest entered number. Use if-else statements for three integer comparison. Example: Enter an integer: 5 Enter an integer: 23 Enter an integer: 7 The smallest number is: 5 Example 2: Enter an integer: 3 Enter an integer: 3 Enter an integer: 6 The smallest number is: 3 "The input must be positive number. The program should...

  • // demonstrates separating digits with a remainder operator // Mikhail Nesterenko // 01/22/2016 #include <iostream> using...

    // demonstrates separating digits with a remainder operator // Mikhail Nesterenko // 01/22/2016 #include <iostream> using std::cin; using std::cout; using std::endl; int main(){ cout << "Input number from 01 to 50: "; int number; cin >> number; const int singles = number % 10; const int tens = number / 10; cout << "tens: " << tens << endl; cout << "singles: " << singles << endl; You may assume that the user never inputs a number less than 1...

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