***Newbie Needs Help With Functions Program ***

Quote:

> 1. long intPower(short base, short exponent)

{// very slow version without errorhandling

long result=1;

if (base == 0) {

if (exponent < 0)

return ERRORVALUE;

else

return 0; // intPower(0,0) := 0 (1 also possible)

}

if (exponent ==0 {

return 1;

}

if (exponent < 0)

if (base>1) // base > 1 follows 0 < 1/base < 1

return 0;

else

return 1;

while (exponent--) {

result *=base; // overflow possible!

}

return result;

Quote:

}

faster version with <math.h>

{

return (long)(pow(base,short)); // check matherr

Quote:

}

> 2. double average(int i, int j, int k, int l)

> average should return the real average of 4 integers sent to

> the function .

{

return ( 1.0 * ( i + j + k + l ) )/4.0;

Quote:

}

> 3. void blankLines(short n)

> the function should be used to produce n number of blank lines

> in the program output.

{

if (n<=0){

return

}

while (n--) {

printf("\n");

}

Quote:

}

> 4. A function theat is sent 5 integers and returns the highest of the

Takes an array on count integer (standart count=5), and returns the

highest one.

int Max(int *in, int count=5) {

int r = *in;

while (--count) {

in++;

if (r < *in) {

r = *in;

}

}

return r;

Quote:

}

Regards

Gert

--

Max-Planck-Institute of Cognitive NeuroSience http://www.cns.mpg.de

Inselstrasse 22-26, 04103 Leipzig, Germany