Programming Exercises

 

1. Population Growth

Write a program that calculates the population of a city over a period of years. The program should ask the user for the initial population, the annual growth rate (as a percentage), and the number of years to simulate.

Use a loop to calculate and display the population at the end of each year.

 

2. Savings Account Balance

Write a program that calculates the balance of a savings account over a period of time. The program should ask the user for the initial balance, the annual interest rate, and the number of years.

Use a loop to display the balance at the end of each year, considering the interest compounding annually.

 

3. Temperature Conversion

Write a program that displays a table of Fahrenheit temperatures 32 through 212 and their Celsius equivalents.

The formula for converting a temperature from Fahrenheit to Celsius is:

F to C function

 

4. Multiplication Table

Write a program that uses nested loops to display a multiplication table for the numbers 1 through 10. The outer loop should iterate over the numbers 1 through 10, and the inner loop should multiply the outer loop variable by each number from 1 to 10.

 

5. Loan Amortization Schedule

Write a program that calculates the amortization schedule for a loan. The program should ask the user for the loan amount, annual interest rate, and number of years for repayment.

Use a loop to display the remaining balance after each monthly payment.

 

6. Factorial Calculation

Write a program that calculates the factorial of a given number using a loop. The factorial of a non-negative integer n is the product of all positive integers less than or equal to n.

 

7. Countdown Timer

Write a program that asks the user for a number of seconds and then counts down to zero, displaying the remaining seconds. The loop should pause for one second between each iteration.

 

8. Prime Numbers

Write a program that asks the user for a number and then uses a loop to determine whether the number is prime. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.

 

9. Sales Tax Calculation

Write a program that calculates the total price of items in a shopping cart, including sales tax. The program should ask the user to enter the price of each item and a sales tax rate.

Use a loop to calculate and display the total price with tax after all items have been entered.

 

10. Interest Earned

Write a program that asks the user for an initial investment amount and an annual interest rate. Use a loop to calculate and display the amount of interest earned each year for a specified number of years. At the end, display the total amount of interest earned.