Javatpoint Logo
Javatpoint Logo

Program to determine whether a given number is a Disarium number

Explanation

In this program, we need to check whether the given number is Disarium or not.

Disarium number

A number is said to be the Disarium number when the sum of its digit raised to the power of their respective positions is equal to the number itself.

For example, 175 is a Disarium number as follows

11 + 72 + 53 = 1 + 49 + 125 = 175

Some of the other examples of Disarium number are 89, 135, 518 etc.

To find whether given number is Disarium or not, calculate the sum of digits powered with their respective positions. If the sum is equal to the original number then, the given number is Disarium number.

Algorithm

  1. calculateLength() counts the digits present in a number.
    1. Use a while loop to check whether the number is not equal to 0.
    2. Divide the number by 10 and increment the variable length by 1.
    3. Return length.
  2. Define and initialize variable num.
  3. Make a copy of num by storing the value of num in n.
  4. Using while loop calculates remainder rem repeatedly by dividing num with 10.
  5. Calculate the value of rem raised to power its position, i.e. remlen and store the computed value in a variable sum.
  6. Check whether sum is equal to number. If yes, then given number is Disarium number. Else, it is not a Disarium number.

Solution

Python

Output:

 175 is a disarium number

C

Output:

175 is a disarium number

JAVA

Output:

175 is a disarium number

C#

Output:

175 is a disarium number

PHP

Output:

175 is a disarium number

Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA