Introduction
Do you know that some numbers, when squared, split into two parts and then added together, give the original number? Do you know that they are called kaprekar numbers? If not, then donâ€™t worry. We will clear all your doubts.
In this article, we will discuss about kaprekar number. We will understand it with the help of an example. We will also talk about its use cases. In the end, we will see the pros and cons of the kaprekar number. Moving forward, letâ€™s first understand what a kaprekar number is.
Also Read About, floyd's algorithm
What is a Kaprekar Number?
A kaprekar number is defined as a nonnegative integer. This number is named after an Indian mathematician D.R. Kaprekar. He discovered kaprekar numbers in 1949. Whenever a number is squared, and its digits are split into two parts in order to make their sum equal to the original number, then that number is called a kaprekar number. Letâ€™s understand it better with the help of an example.
Letâ€™s suppose we have a number 55.

On squaring 55, it will give 3025.

Now, splitting it into two parts will give 30 and 25.

Now, if we add these two parts together, then we will again get number 55(30+25).
Moving forward, letâ€™s see its program to understand its logic better.
Code
Output
Explanation
In the above code, we have made a NinjaClass, inside which we have made a function named kaprekar. This function checks whether the number is kaprekar or not and returns true or false on the basis of it. If true is returned, then it prints that particular number is a kaprekar number. According to the above output, we can say that between 1 and 100, there are 5 kaprekar numbers, which are, 1, 9, 45, 55, and 99.