Ask Question
13 March, 15:46

Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm should separate the digits of the number and print each in a line starting from the number at one's place, then the number at ten's place, and so on. Example: if user inputs 329, then the algorithm should produce the following three lines.

9

2

3

+4
Answers (1)
  1. 13 March, 16:43
    0
    Algorithm:

    1. Declare an integer variable N.

    2. Read the value N from user.

    3. While (N):

    3.1 find r=N%10;

    3.2 print r in new line.

    3.3 Update N as N=N/10.

    4. end program.

    Implementation in C++.

    / / header

    #include

    using namespace std;

    / / main function

    int main ()

    {

    / / variable

    int N;

    cout<<"Enter an Integer:";

    cin>>N;

    / / find the digits of number

    while (N)

    {

    / / last digit

    int r=N%10;

    / / print last digit

    cout<
    / / update the number

    N=N/10;

    }

    return 0;

    }

    Output:

    Enter an Integer:329

    9

    2

    3
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm should ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers