C Programming

Practise Exercise 8: Functions

1. Write a function called menu which prints the text string "Menu choices". The function does not pass any data back, and does not accept any data as parameters.


	void menu( void )
	{
		printf("Menu choices");
	}

2. Write a function prototype for the above function.


	void menu( void );

3. Write a function called print which prints a text string passed to it as a parameter (ie, a character based array).


	void print( char message[] )
	{
		printf("%s, message );
	}

4. Write a function prototype for the above function print.


	void print( char [] );

5. Write a function called total, which totals the sum of an integer array passed to it (as the first parameter) and returns the total of all the elements as an integer. Let the second parameter to the function be an integer which contains the number of elements of the array.


	int total( int array[], int elements )
	{
		int loop, sum;
		
		for( loop = 0, sum = 0; loop < elements; loop++ )
			sum += array[loop];
		return sum;
	}

6. Write a function prototype for the above function.


	int total( int [], int );


ęCopyright B Brown. 1984-1999. All rights reserved.