You are on page 1of 1

C PROGRAMMING

FUNCTIONS (DEFINITION, DECLARATION & CALL)

LAB EXERCISES
INTRODUCTION
Go through the lecture notes on functions I to familiarize yourself with the concepts

Practice
in the image above :) Let’s use shape 1 as
an example.
4. Type in the code below and run it

printf("Shape 1\nIt contains a semi-circle and a


rectangle.\n");
area = circle(4)/2 + rectangle(12,8);
printf("Area of shape 1 = %.2fft\n\n ", area);

5. Study the code to understand how it works


6. Now complete the worksheet by writing
similar code to output the areas of the
other compound shapes.
7. Further your practice with new functions of
your choice. Below is another worksheet.

1. Write four different functions, each for


calculating the area of the following
shapes: square, circle, triangle and
rectangle. The functions should receive the
shape dimensions as float arguments and
return the area of the shape in float
format.
Note: Pay attention to the syntax of
function declarations, definitions and
calls.
2. Within your main function, declare a
variable called area of type float.
3. You are going to write a program to
calculate the area of the compound shapes

T-S ADJAIDOO 1

You might also like