0
   

Looping is hard but have to get a good grade

 
 
Reply Mon 24 Feb, 2014 01:28 pm
Read a positive integer value (validation), and compute the following sequence:

If the number is even, halve it;
If it is odd, multiply by 3 and add 1.

Repeat this process until the value is 1 or a negative number, printing out each value.

Finally print out how many of these operations you performed.

If the number ends at 1 print out that the number is a happy number.
If the number doesn't end at 1, print out that the number is a sad number.

Allow the user to enter another number if they want to see if it is a happy or sad number.

Ex.
enter number is 12
12
6
3
10
5
16
.
.
.
This is to be made using only looping
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 528 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Looping is hard but have to get a good grade
Copyright © 2025 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 02/10/2025 at 09:47:42