<mosaic.cnfolio.com>
Introduction to Algorithms and Programming – ENG421

# ENG421 Practice worksheet 2 – Calculator programs

## The online compiler

• The first textbox is used to write the source code for the C program.
• The second textbox is used to type text that is intended to be input for the program when it is running. Leave this box empty when there is no input.
• The third box is used to display the output from compiling and running the program.
• Click the Run program button to compile and run the C program.

## Question 1

Write programs to calculate the volume of each shape in the list below:
1. cube
2. cylinder
3. prism
4. sphere
5. pyramid
6. cone

Read this Wikipedia article to find the formulas to calculate the volume of different shapes:

Test your program with different input values.

## Question 2

Write programs to calculate the total parking tariff for each type of input:
1. parking duration in minutes
2. start time and end time for parking duration

Use the parking tariff provided on this website for sample calculations:

Test your program with different input values.

## Simple interest

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added just once at the end of an investment duration consisting of N years. Let V be the total value including the investment and interest earned.

IMAGE NOT AVAILABLE

## Question 3

Write a program to calculate simple interest and display annual investment values:
1. Read initial investment input value
2. Read annual interest rate input value
3. Read number of years input value
4. Display the investment values based on simple interest at the end of years 1 to 5
5. Display the final investment value

Test your program with different input values.

## Compound interest

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added at the end of each investment period, which is called compounding. Let N be the number of years during the whole investment duration. Let V be the total value including the investment and interest earned.

IMAGE NOT AVAILABLE

## Question 4

Write a program to calculate compound interest and display annual investment values:
1. Read initial investment input value
2. Read annual interest rate input value
3. Read number of years input value
4. Display the amount of compound interest earned at the end of years 1 to 5
5. Display the final investment value

Test your program with different input values.