<<< Functions, cont. | Index | Data for iteration: vector >>> |
Earlier we looked at code to find the larger of two values. Here is a function that compares the two values and returns the larger value:
int max( int a, int b ) // this function takes 2 parameters { if ( a < b ) { return b; } else { return a; } }
Usage example:
int x = max( 7, 9 ); // x becomes 9 int y = max( 19, -27 ); // y becomes 19 int z = max( 20, 20 ); // z becomes 20
<<< Functions, cont. | Index | Data for iteration: vector >>> |