While Loop Exercises
1. Using a while loop print the following pattern.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2. Ask the user for a number positive integer less than 100 and create a sequence of numbers that adheres to the following pattern and displays the number of iterations of the loop. Display an error message if the user enters an invalid number.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2. Ask the user for a number positive integer less than 100 and create a sequence of numbers that adheres to the following pattern and displays the number of iterations of the loop. Display an error message if the user enters an invalid number.
- If the number is odd, multiply by 3 and add 1
- If the number is even, divide by 2
- Stop when the answer is 1