Difference between revisions of "Looping Exercises"
From WLCS
Line 3: | Line 3: | ||
'''Directions:''' | '''Directions:''' | ||
− | * For each of the following sequences, first prompt the user for a number N and print out the first N terms of the sequence | + | * For each of the following sequences, '''first prompt the user for a number N and print out the first N terms of the sequence''' |
* Creating functions for the following exercises is optional | * Creating functions for the following exercises is optional | ||
* Use while loops to generate the following sequences | * Use while loops to generate the following sequences | ||
+ | |||
* Powers of 3 | * Powers of 3 | ||
** 1, 3, 9, 27, 81, ... | ** 1, 3, 9, 27, 81, ... | ||
+ | |||
* Fibonacci Sequence (HINT: use multiple variables) | * Fibonacci Sequence (HINT: use multiple variables) | ||
** 0, 1, 1, 2, 3, 5, 8, 13, 21, ... | ** 0, 1, 1, 2, 3, 5, 8, 13, 21, ... | ||
+ | |||
* Factorial Sequence (HINT: use multiple variables) | * Factorial Sequence (HINT: use multiple variables) | ||
** 1, 1, 2, 6, 24, 120, ... | ** 1, 1, 2, 6, 24, 120, ... |
Revision as of 11:43, 19 November 2010
Objective:
- To become well-learned in the way of the while loop
Directions:
- For each of the following sequences, first prompt the user for a number N and print out the first N terms of the sequence
- Creating functions for the following exercises is optional
- Use while loops to generate the following sequences
- Powers of 3
- 1, 3, 9, 27, 81, ...
- Fibonacci Sequence (HINT: use multiple variables)
- 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
- Factorial Sequence (HINT: use multiple variables)
- 1, 1, 2, 6, 24, 120, ...