Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If we input a number formed by 4 digits and these digits are not all of the same value, then it obeys the following law.

image text in transcribed

If we input a number formed by 4 digits and these digits are not all of the same value, then it obeys the following law. Let us process the number in the following way: 1. Arrange the digits in the way from bigger to smaller, such that it forms the biggest number that could be made from these 4 digits 2. Arrange the digits in the way from smaller to bigger, such that it forms the smallest number that could be made from these 4 digits (If there is 0 among these 4 digits, the number obtained may be less than four digits); 3. Find the difference of these two numbers that is a new four digital number Repeat the above process (1-3), we get the result 6174 or 0 Write the program to implement the above algorithm. The output from the program should show the procedure for finding this number and the number of repetitions. Sample Input Sample Output N-5364: 6543-3456-3087 8730-378-8352 8532-2358-6174 Ok!! 3 times N-2221: 2221-1222-999 999-999-0 Ok!! 2 times N-4444 No!! 5364 2221 -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

5. Describe how contexts affect listening

Answered: 1 week ago