INTRODUCTION TO C PROGRAMMING CE00312-1
Source: www.soc.staffs.ac.uk
Topic: C Programming
Short Desciption:Page 1 INTRODUCTION TO C PROGRAMMING CE00312-1 TUTORIAL / PRACTICAL No. 3 1. Implement each of the following functions a) - d) and write a testbed program to call each function.
Content Inside:
Page 1
INTRODUCTION TO C PROGRAMMING
CE00312-1
TUTORIAL / PRACTICAL No. 3
1. Implement each of the following functions a) - d) and write a testbed program to call
each function. The testbed accepts a character to select a function, reads values
required to test the function, calls the function which calculates the result, returning it
to main() from where it is printed. This is performed repeatedly until q (for quit) is
input.
i. The testbed should be implemented first and should initially output "function x not
yet implemented" for each valid selection x, or report erroneous selections.
ii. Add the following functions one at a time to the testbed. Note that all input and
output must occur in the testbed i.e. in main().
a)
A function mult(x,y) which returns the value of x*y where x and y are integers.
b)
A function find_abs(x) which returns the absolute value of the double precision
floating point argument x. e.g. find_abs(3.0) produces 3.0, find-abs(-3.0) gives 3.0
c)
A function fact(x) which returns x! ( x factorial ) where x is an integer
d)
A function power(x,y) which returns x to the power of y, where x is a floating
point and y is a positive integer e.g. power(3.0,4) gives 81.0 i.e. 3.04. Hint.use
repeated multiplication.
iii. Finally, add a function to print a menu for the selections and incorporate this in your
program.
You should incorporate the switch statement and take care when processing characters.
You should refer to Lecture 3 to remind yourself of how to input and process characters,
paying attention to the return key. Comments should be used throughout.
Your tutor will explain in the tutorial how to do "double reads" when character and
integer input needs to be mixed.
"Build a little - test a little" is a recommended approach to programming. Namely
modify programs slightly, then recompile. Yes, more compilations are needed -
but you dont get "swamped" with ...

