Anyone have code with this?...


Write a program to find the chain associated with any given number.
Start with the given positive integer. This is the first number in the chain. Sort the digits
(of the base 10 number) into ascending order, and also in descending order. Subtract
the ascending number from the descending number. This is the next number in the
chain. Continue until you find a cycle.
Input will consist of a number of at most 6 digits, and the chain will repeat within 20
steps.
The output should show each step in finding the chain along with both the length until
the chain is identified and the length of the chain.


Examples

Example 1:
Enter an integer: 56472
76542 - 24567 = 51975
97551 - 15579 = 81972
98721 - 12789 = 85932
98532 - 23589 = 74943
97443 - 34479 = 62964
96642 - 24669 = 71973
97731 - 13779 = 83952
98532 - 23589 = 74943
Length until repeat: 8
Length of chain: 4

Example 2:
Enter an integer: 893
983 - 389 = 594
954 - 459 = 495
954 - 459 = 495
Length until repeat: 3
Length of chain: 1

Sure. Will we give it to you, no. We are here to help you correct your code, we are not here to do your (home)work for you. If that is all you are looking for go here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.