Ask Question
14 March, 20:44

Write a program that inputs a non negative integer, separates the integer into its digits and prints them separated by tabs each. For example, if the user types in 42339, the program should print:42339

+4
Answers (1)
  1. 14 March, 23:36
    0
    tab = ""

    number = int (input ("Enter a nonnegative integer: "))

    while number:

    digit = number % 10

    if len (str (number)) ! = 1:

    tab + = str (digit) + "/t"

    else:

    tab + = str (digit)

    number / / = 10

    print (tab[::-1])

    Explanation:

    * The code is in Python

    - Initialize an empty string to hold the digits

    - Ask the user for the input

    Inside the loop:

    - Get the digits of the number. If the length of the number is not 1 (If it is not the first digit), put a tab between the digits. Otherwise, just put the number (This will get the numbers from the last digit. If number is 123, it gets 3 first, then 2, then 1)

    - Print the string in reverse order
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that inputs a non negative integer, separates the integer into its digits and prints them separated by tabs each. For ...” 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