Javatpoint Logo
Javatpoint Logo

C Program to check if the given number is a Disarium Number

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 becomes equal to the number itself.

For example, 175 is a Disarium number as follows:

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

ALGORITHM:

main()

  • STEP 1: START
  • STEP 2: DEFINE n
  • STEP 3: SET num =175, sum =0, rem =0
  • STEP 4: len = calculateLength(num)
  • STEP 5: n =num
  • STEP 6: REPEAT STEP 7 to 10 UNTIL (num>0)
  • STEP 7: rem = num%10
  • STEP 8: sum =sum + (rem)len
  • STEP 9: num = num/10
  • STEP 10: len--
  • STEP 11: if(sum==n) then PRINT "Yes" else PRINT "No"
  • STEP 12: RETURN 0
  • STEP 13: END

calculateLength(n)

  • STEP 1: START
  • STEP 2: SET length =0
  • STEP 3: REPEAT STEP 4 and STEP 5 UNTIL (n!=0)
  • STEP 4: length = length+1
  • STEP 5: n =n/10
  • STEP 6: RETURN length
  • STEP 7: END

PROGRAM:

Output:

175 is a disarium number
Next TopicC Programs




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA