Question

given an integer, write a program that displays the number as follows first line         all digits...

given an integer, write a program that displays the number as follows
first line         all digits
second line   all except first digit
third line        all except first two digits
.....
last line          the last digit

ex)
5 6 7 8
6 7 8
7 8
8

Homework Answers

Answer #1

Explanation:

Here is the program which takes n as input from the user and then uses 2 for loops to print the pattern mentioned in the problem.

Code:


n = input("Enter an integer: ")

for i in range(len(n)):
for j in range(i, len(n)):
print(n[j], end=' ')
print()
  

output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Know the answer?
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
Similar Questions
given an integer, write a program in C++ that displays the number as follows first line        ...
given an integer, write a program in C++ that displays the number as follows first line         all digits second line   all except first digit ... last line          last digit ex) 5 6 7 8 6 7 8 7 8 8
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
write a C program to find whether the given number of three digits is an integer...
write a C program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371. Output: Enter a number, or -999 to quit : 432 4**3 + 3**3 + 2**3 is not = 432 Enter a number, or -999 to quit : 371 3**3 + 7**3 + 1**3 is = 371...
How to write a C++ program. Additive persistence is a property of the sum of the...
How to write a C++ program. Additive persistence is a property of the sum of the digits of an integer. The sum of the digits is found, and then the summation of digits is performed creating a new sum. This process repeats until a single integer digit is reached. Consider the following example: 1. The beginning integer is 1234 2. Sum its digits is 1+2+3+4 = 10 3. The integer is now 10 4. The sum of its digits is...
Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond...
Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 5, the program should display c++ look like a diamond
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15 Note: You must use integer division and modulo division to...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and...
[10 marks] (SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15
in java Write a program that displays all the leap years, eight per line, from 101...
in java Write a program that displays all the leap years, eight per line, from 101 to 2500, separated by one space. Meanwhile display the number of leap years in this period of year.
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
Write a C program that creates a security access code from a social security number entered...
Write a C program that creates a security access code from a social security number entered by a user as follows: Using a recursive function it adds all of the digits of the social security number and then using a regular function gets the square number of the sum and displays it. The access code displayed should be initialized as an integer number but using type casting is displayed as a floating number.