1)
a) (For Loop) Print all Number from 1 to 20
b) (For Loop) Print all Number from 10 to 20
2)
a) (For Loop) Write a program that prints all of the odd integers between 1 and 101.
b) (For Loop) Write a program that SUMS all of the odd integers between 1 and 101 and prints the sum.
3)
a) (For Loop) Write a program that prints all of the even integers between 2 and 100.
b) (For Loop) Write a program that sums all of the even integers between 2 and 100 and prints the sum.
4) (For Loop) Write a program that prints all of the multiple of 3's between 3 and 102.
5) Write a program that sums all of the integers between two input numbers, inclusive:
Enter starting number: 25
Enter ending number: 47
The sum of integers from 25 to 47 is 828
6. Amy's Garden Emporium needs mailing labels for their shipping boxes. Write a program to print a mailing label for each box to be shipped:
How many boxes? 2
AMY'S GARDEN EMPORIUM
SUNTAN, IOWA 12345
Box Number 1 of 2
AMY'S GARDEN EMPORIUM
SUNTAN, IOWA 12345
Box Number 2 of 2
7. Write a program that asks the user for starting and ending values and then prints the following table of numbers using formatted output:
Enter starting value: 5
Enter ending value: 12
X X SQUARED X CUBED
5 25 125
6 36 216
.
.
12 144 1728
8. Find the sum of all the odd numbers and print a table of values giving this sum for maximum values of 1 through 50:
Number Sum
1 1
2 1
3 4
4 4
5 9
6 9
48 576
49 625
50 625
9. a) The factorial of a positive number is the product of all positive integers less than or equal to the number. For example, 5 factorial (written 5!) is equal to 5 * 4 * 3 * 2 * 1, or 120. Write a program that reads a positive integer and prints its factorial:
Enter an integer: 5
5! = 120
b) 0! is defined as 1, but all negative factorials are considered to be undefined. Modify your factorial program to correctly handle these cases:
Example 1
Enter an integer: 5
5!=120
Example 2
Enter an integer: -3
-3! is undefined.
Example 3
Enter an integer: 0
0! = 1
10. a) Write a program that calculates the average and total for a known number of test grades. First, read in the number of grades, then the grades.
How many grades? 12
Enter a grade: 95
Enter a grade: 75
Enter a grade: 69
The total is 1020
The average is 85.00
11. a) Write a program that reads in letter grades for a class of 20 students. Keep track of the number of students who passed (D or better), and the number who failed (E or F).
Enter a grade: C
Enter a grade: E
Enter a grade: B
16 students passed
4 students failed
b) Change your program to work for a class of unknown size. Stop processing grades when a Z is entered, making sure not to count the Z as a grade. Also, calculate and print the percentage of students passing and failing using formatted output: (USE The Break)
Enter a grade: C
Enter a grade: E
Enter a grade: A
Enter a grade: Z
12 students passed: 80.00 %
3 students failed: 20.00 %
Nested For Loops
12) Use NESTED FOR LOOPS to create the Multiplication table
1 |
2 |
3 |
4 |
5 |
2 |
4 |
6 |
8 |
10 |
3 |
6 |
9 |
12 |
15 |
4 |
8 |
12 |
16 |
20 |
5 |
10 |
15 |
20 |
25 |
6 |
12 |
18 |
24 |
30 |
13. Use NESTED FOR LOOPS and 2 cout statements to produce the following output.
* |
|
|
|
|
|
* |
* |
|
|
|
|
* |
* |
* |
|
|
|
* |
* |
* |
* |
|
|
* |
* |
* |
* |
* |
|
* |
* |
* |
* |
* |
* |