4-Iteration-exercise
4-Iteration-exercise
4. Create a program that prompts the user for a number and displays the table
of that number.
5. Create a program that displays the table of all numbers from 1 to 10.
6. Write a program that calculates and displays the values of the power of a
number entered by the user raised to an exponent also entered by the user.
7. Write a program that prompts the user for two numbers A and B and
displays all numbers between A and B.
8. Write a program that asks the user for a number N and displays the sum of
all numbers from 1 to N.
9. Write a program that prints all even numbers from 1 to 100 using a loop
without using any if statement.
10. Write a program that reads numbers from the user until a negative number
is entered, and prints the sum of the positive numbers.
11. Write a program that calculates and displays the sum of even numbers
from 1 to 100 using a repeating loop.
12. Write a program that reads numbers from the user until zero is entered,
and displays the average of the numbers entered.
13. Develop a class averaging program that will process an arbitrary number of
marks each time the program is run.(Sentinel Value)
14. Drivers are concerned with the mileage obtained by their automobiles. One
driver has kept track of several tank fills of gasoline by recording miles driven
and gallons used for each tankful. Develop a program that will input the miles
driven and gallons used for each tankful. The program should calculate and
display the miles per gallon obtained for each tankful. After processing all input
information, the program should calculate and print the combined miles per
gallon obtained for all tank fills. Here is a sample input/output dialog:
17. Write a program that uses looping to print the following table of values.
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8 80 800 8000
9 90 900 9000
18. Write a program that utilizes looping to produce the following table of
values:
3 5 7 9
6 8 10 12
9 11 13 15
12 14 16 18
15 17 19 21
19. Write a program that reads in the side of a square and then prints that
square out of asterisks. Your program should work for squares of all side sizes
between 1 and 20. For example, if your program reads a size of 4, it should
print
****
****
****
****
20. One interesting application of computers is drawing graphs and bar charts
(sometimes called “histograms”). Write a program that reads an number
(between 1 and 30) and print a line containing that number of adjacent
asterisks. For example, if your program reads the number seven, it should print
*******
====================Sequence + Selection=======================
21. Write a program that prints all even numbers from 1 to 10 using a loop and
an if statement inside the loop to check if the number is even or not.
22. Write a program that prompts the user for a list of numbers, until the user
types the number zero, and displays the largest and smallest numbers in the
list.
23. Develop a program that will determine the gross pay for each of several
employees. The company pays “straight time” for the first 40 hours worked by
each employee and pays “time-and-a-half” for all hours worked in excess of 40
hours. You’re given a list of the employees of the company, the number of
hours each employee worked last week and the hourly rate of each employee.
Your program should input this information for each employee, and should
determine and display the employee's gross pay. Here is a sample input/output
dialog:
Salary is $390.00
Enter # of hours worked (-1 to end): 40
Salary is $400.00
Salary is $415.00
24. Write a program that reads in the side of a square and then prints a hollow
square. For example, if your program reads a size of 5, it should print
*****
* *
* *
* *
*****
25. Write a program that reads an integer and determines and prints how
many digits in the integer are 7s.