Home > Programming > Functions using the "C" programming language > example06.c

 

Previous

Next


/*
    In this example we demonstrate the ability of passing array parameters
    of variable size.
    We 'll use the function print_float to print the array elements.
*/

#include <stdio.h>
#define SIZE1 5
#define SIZE2 10

/* Function prototype */
void print_float( float nums[ ], int );

/* Main programm */
void main(void)
{
/* Initial values for an array of float with 5 elements */
    float a1[SIZE1] = { 10, 20, 30, 40, 50 };
/* Initial values for an array of float with 10 elements */
    float a2[SIZE2] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

    print_float( a1, SIZE1 );
    print_float( a2, SIZE2 );
}

/* print_float function code */
void print_float( float nums[ ], int x )
{
    int i;
    for( i = 0 ; i < x ; i++ ) printf(" %f \n ", nums [ i ] );
}


© 2004 Jim Valavanis

Previous

Next

1