Loops
& Selection Structures
1.
Write a program that prints the even numbers from 100 to -10
backwards with a space between each number using a
a. for loop. b.
while loop. c.
do while loop.
(5 pts)
2.
Using if and if/else statements, write some code that tests
the size of a number, prints "pretty dag gone big" if it's bigger
than 10 000, "teensie weensie" if it's less than 10, and
"mediocre" otherwise. No
matter what the number is should print "Adios" after the test. (5 pts)
3.
Prompt the user for an int from 1 to 20. Don't accept numbers bigger or smaller. Then print "The Three Stooges
Rule!" the number of times the user entered. Number each line so that the lines are being counted. (5 pts)
4.
Print all the three digit whole numbers in rows with seven
numbers in a row. Use the loop of your
choice. You'll need the modulo
operator. (5 pts)
5.
Create three columns.
The first should have the ints 10 down to 1, the second should have
their squares, and the third should say if the square is over fifty or not. (5 pts)
6.
Use nested for loops to print:
1
1 2
1 2 3 etc. until you reach the line
that prints up to the number 10. (10
pts)
7.
Find the sum of all integers, n, from 2 to 100 such that n4 - n3 + 3n has a ten's digit of two. (10 pts)
8. (fairly high difficulty, but not unreasonable for a quiz) Write a program that repeatedly prompts the user for a character called letter, which represents the employment status of person at a company until the user enters a period. R is for retired, A is for active duty, F is for former employees, S is for employees currently on sick leave, and V is for employees currently on vacation. Using a switch statement, the program should count the number of people in each category. In addition, when the user enters an A for active duty, s/he should be further prompted to enter the year of the employee's starting date. After all employees are entered, a table of results should be printed along with the starting year of the active employee with the most experience. If a meaningless letter is entered, an appropriate message should be displayed. (20 pts)
9. Create your very own Christmas tree with ten rows using nested for loops:
*
***
*****
*******
(15 pts)
10. Write a program that counts the number of digits in an arbitrarily large integer. Hint: This is a short program (I did it in ten lines) that should make use of a while loop. (10 pts)
11. Write a loop that tests all three digit numbers to see if the sum of digits is greater than 6. All numbers that pass the test should be outputted in a table format with five numbers per row. Use the modulo operator and the conditional operator to print the output in rows. (15 pts)
12. Make a loop that prints out every other letter of the alphabet. ('A' corresponds to the number 65.) (5 pts)