Javatpoint Logo
Javatpoint Logo

C program to print all disarium numbers between 1 to 100

In this program, we need to print all disarium numbers between 1 and 100 by following the algorithm as given below:

ALGORITHM:

main()

  • STEP 1: START
  • STEP 2: SET result =0
  • STEP 3: PRINT statement "Disarium numbers between 1 and 100 are"
  • STEP 4: REPEAT STEP 5 &6 UNTIL (i<=100)
  • STEP 5: result = sumOfDigits(i)
  • STEP 6: if(result==i) then PRINT i
  • STEP 7: RETURN 0
  • STEP 8: END

sumOfDigits(num)

  • STEP 1: START
  • STEP 2: SET sum =0, rem =0
  • STEP 3: len = calculateLength(num)
  • STEP 4: REPEAT STEP 5 to 8 UNTIL (num>0)
  • STEP 5: rem = num%10
  • STEP 6: sum = sum + (rem)len
  • STEP 7: num =num/10
  • STEP 8: len--
  • STEP 9: RETURN sum
  • STEP 10: END

calculateLength(int n)

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

PROGRAM:

Output:

Disarium numbers between 1 and 100 are
1  2  3  4  5  6  7  8  9  89

Happy Number

A number is said to be happy if it yields 1 when replaced by the sum of squares of its digits repeatedly. If this process results in an endless cycle of numbers containing 4, then the number will be an unhappy number.

Let's understand by an example:

Number = 32
32+ 22 = 13
12 + 32 = 10
12 + 02 = 1

In this example, we split 32 to get the sum of squares of its digits which forms another number (13), we replace 32 by 13 to continue this cycle until result 1. We found 32 a happy number.

If the above cycle for any number results 1 then that number will be a Happy number otherwise that will be an unhappy number resulting 4, 16, 37, 58, 89, 145, 42, 20,??

Some Happy numbers are 7, 28, 100, 320 etc.

Next TopicC Programs





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA