What is Magic Number?

A magic number is that number whose sum of its digits is when multiplied by the reverse of the sum of its digits gives back the same number.

E.g 1729

Magic number in C

Steps to Check Magic Number in C

  1. Input a number.
  2. Copy the original number into another variable i.e temp.
  3. Using while loop and mod (%) operator, add the digits of temp and store it in sumOfDigits.
  4. Copy the value of sumOfDigits into temp.
  5. Using while loop on temp, compute reverse of temp (i.e of sumOfDigits) and store it in rev.
  6. Check if rev ==  sumOfDigits.
  7. If Yes, then the given number is Magic number else not.

C Program

Output of Program

C Program for magic Number

If you have any problem with the code, then share it in comments.

Leave a Reply

Close Menu