0% found this document useful (0 votes)
12 views

4-Iteration-exercise

The document contains a list of programming tasks that involve basic programming concepts such as loops, conditionals, user input, and calculations. Each task specifies a different requirement, ranging from displaying numbers, calculating sums and averages, to creating shapes and processing user data. The tasks are designed to help users practice and enhance their programming skills.

Uploaded by

ahmedkhwaja193
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

4-Iteration-exercise

The document contains a list of programming tasks that involve basic programming concepts such as loops, conditionals, user input, and calculations. Each task specifies a different requirement, ranging from displaying numbers, calculating sums and averages, to creating shapes and processing user data. The tasks are designed to help users practice and enhance their programming skills.

Uploaded by

ahmedkhwaja193
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. Write a program that displays all numbers from 1 to 100.

2. Write a program that displays the number 1 through 10.

3. Write a program that displays even numbers 1 to 50 and odd numbers 51 to


100.

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:

Enter the gallons used (-1 to end): 12.8

Enter the miles driven: 287

The miles / gallon for this tank was 22.421875

Enter the gallons used (-1 to end): 10.3

Enter the miles driven: 200

The miles / gallon for this tank was 19.417475

Enter the gallons used (-1 to end): -1


15. One large chemical company pays its salespeople on a commission basis.
The salespeople receive $200 per week plus 9% of their gross sales for that
week. For example, a salesperson who sells $5000 worth of chemicals in a
week receives $200 plus 9% of $5000, or a total of $650. Develop a program
that will input each salesperson’s gross sales for last week and will calculate
and display that salesperson's earnings. Process one salesperson's Salary at a
time. Here is a sample input/output dialog:

Enter sales in dollars (-1 to end): 5000.00

Salary is: $650.00

Enter sales in dollars (-1 to end): 1234.56

Salary is: $311.11

Enter sales in dollars (-1 to end): 1088.89

Salary is: $298.00

Enter sales in dollars (-1 to end): -1

16. The simple interest on a loan is calculated by the formula interest =


principal * rate * days / 365; the preceding formula assumes that rate is the
annual interest rate, and therefore includes the division by 365 (days). Develop
a program that will input principal, rate and days for several loans, and will
calculate and display the simple interest for each loan, using the preceding
formula. Here is a sample input/output dialog:

Enter loan principal (-1 to end): 1000.00


Enter interest rate: .1

Enter term of the loan in days: 365

The interest charge is $100.00

Enter loan principal (-1 to end): 1000.00

Enter interest rate: .08375

Enter term of the loan in days: 224

The interest charge is $51.40

Enter loan principal (-1 to end): -1

17. Write a program that uses looping to print the following table of values.

N 10*N 100*N 1000*N

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

10 100 1000 10000

18. Write a program that utilizes looping to produce the following table of
values:

A A+2 A+4 A+6

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:

Enter # of hours worked (-1 to end): 39

Enter hourly rate of the worker ($00.00): 10.00

Salary is $390.00
Enter # of hours worked (-1 to end): 40

Enter hourly rate of the worker ($00.00): 10.00

Salary is $400.00

Enter # of hours worked (-1 to end): 41

Enter hourly rate of the worker ($00.00): 10.00

Salary is $415.00

Enter # of hours worked (-1 to end): -1

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.

You might also like