1. Function in C language for returning largest of three integers:
int largest ( int x, int y, int z )
{
if ( x < y ) {
if ( y < z ) return z;
return y;
}
if ( x < z ) return z;
return x;
}
2. Function for finding absolute value:
float absolute ( float a )
{
float b;
b = a;
if ( a < 0 ) b = -b;
return b;
}
"double" can be used instead of "float" to allow numbers with more significant digits.
3. Function for checking for prime:
int prime ( int x )
{
int n, a = 1;
n = x;
if n < 0 n = -n;
do
{
if ( n % a++ == 0 ) return 0;
} while ( n > a * a );
return 1;
}