Problem

Examples

Rectangular Box

Write a program that prompts the user for two ints, a width and a height, and then prints the border of an unfilled box with the given dimensions, using asterisks (*).

width = 5, height = 4

* * * * *

*       *

*       *

* * * * *

width = 3, height = 7

* * *

*   *

*   *

*   *

*   *

*   *

* * *

Triangular Numbers

Write a program that prompts the user for int n, and prints out the nth triangle number, where a triangular number is the sum of all positive integers between 1 and n, inclusive.

Bonus: Find an alternate way to do this without a loop.

n = 3  6

n = 5  15

n = 10  55

n = 21 231

n = 532 141778

Factors

Write a program that prompts the user for positive integer n, and prints out a list of all of the factors of that number.

n = 27

1, 3, 9, 27

n = 32

1, 2, 4, 8, 16, 32

n = 53

1, 53

Prime Numbers

Write a program that prompts the user for positive integer n, and prints out a list of all of the prime numbers up to and including n.

Bonus: there are many solutions to this problem. Once you have a basic working algorithm, consider optimizations you might be able to make. Checking

n = 100

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89

97

Anagrams

Write a program that prompts the user for two strings, and prints "True" if they are anagrams of one another, or "False" otherwise. Your program should ignore case.

evil, vile → True

cheater, teacher → True

python, java → False

train, brain → False

Palindromes

Write a program that prompts the user for a string, and prints "True" if the string is a palindrome, and "False" otherwise.

rotator → True

cinnamon → False

deified → True

racecar → True