Javatpoint Logo
Javatpoint Logo

C program to print all happy numbers between 1 to 100

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

ALGORITHM:

main()

  • STEP 1: START
  • STEP 2: PRINT statement "List of Happy Numbers between 1 and 100:"
  • STEP 3: REPEAT STEP 4 to STEP 7 UNTIL (i<=100)
  • STEP 4: result = i
  • STEP 5: REPEAT STEP 6 UNTIL (result!=1 && result!=4)
  • STEP 6: result = isHappyNumber(result)
  • STEP 7: if(result==1) then PRINT i
  • STEP 8: RETURN 0
  • STEP 9: END

isHappyNumber(int num)

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

PROGRAM:

Output:

List of happy numbers between 1 and 100:
1  7  10  13  19  23  28  31  32  44  49  68  70  79  82  86  91  94  97  100 
Next TopicC Programs




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA