99
We have now the value assignment nested loop we saw before, followed by a similar
set of loops to read and display the values after they are stored. The only new item is
the “%8.2f” which specifies that each value will be displayed in an area of at least 8
characters, with two decimal places (right flush).
.
R U N
.
.
1
.
.
2
.
.
3
.
.
4
.
.
5
.
.
6
.
.
7
.
.
8
.
.
9
.
.
1.00 2.00 3.00
4.00 5.00 6.00
7.00 8.00 9.00
>_
6.2.6 Defining functions
Function definition and program modules
Besides the standard functions, the C programming language lets you define your
own routines as functions to be called by later programs. We have seen a hint of this
already in the “main()” first line of our programs to define them as main functions.
Using the procedures presented here, you will ba able to break large programs down
into modules and then call up each module from the main() function. This means that
you will eventually build up your own library of functions that you can call up from
various programs as you need them.
Creating functions
The following is the format for function definition:
function type declaration function name (arguments)
argument type declaration;
{
declaration of variables used in the function
statements…
}
Function type
This part of the function declares the type of data that will be returned by the function.
This line may be omitted if the value to be returned is an integer (int) or if there is no
data returned. But a good programming discipline is to formally declare an “int” type
or a “void” type when nothing is returned.
Function name
You cannot use reserved words as function names, and you should not use names
already used for standard function names The following is a table of reserved words.
auto
default
float
register
(struct)
(volatile)
break
do
for
return
switch
while
case
double
goto
short
(typedef)
char
else
if
signed
(union)
const
(enum)
int
sizeof
unsigned
continue
extern
long
static
void
The standard functions are listed on page 113