6174 is the Kaprekar Constant. This number is special as we always get this number when following steps are followed for any four digit number such that all digits of number are not same, i.e., all four digit numbers excluding (0000, 1111, …)
- Sort four digits in ascending order and store result in a number “asc”.
- Sort four digits in descending order and store result in a number “desc”.
- Subtract number larger number from smaller number, i.e., abs(asc – desc).
- Repeat above three steps until the result of subtraction doesn’t become equal to the previous number.
We always end up with 6174.
Following is the program to demonstrate the same.
6174 6174 6174
n = 2324 1) asc = 2234 2) desc = 4322 3) Difference = 2088 4) Repeating above steps as difference is not same as n n = 2088 1) asc = 0288 2) desc = 8820 3) Difference = 8532 4) Repeating above steps as difference is not same as n. n = 8532 1) asc = 2358 2) desc = 8532 3) Difference = 6174 4) Repeating above steps as difference is not same as n. n = 6174 1) asc = 1467 2) desc = 7641 3) Difference = 6174 Stopping here as difference is same as n.
This article is contributed by Gaurav Saxena. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Kaprekar Number
- Find Index of given fibonacci number in constant time
- Tau - A Mathematical Constant
- Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant
- Kth number from the set of multiples of numbers A, B and C
- Find the previous fibonacci number
- Find the quadratic equation from the given roots
- Smallest N digit number which is a perfect fourth power
- Angle subtended by an arc at the centre of a circle
- Count of 0s in an N-level hexagon
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Count of elements on the left which are divisible by current element
- Find the minimum value of X for an expression
- Sum of the count of number of adjacent squares in an M X N grid
Improved By : Mithun Kumar