|
|
Function Example |
|
#include <stdio.h>
/* function prototype */
int power ( int num, int exp );
/*
* Main procedure
*/
int main ( void ) {
int i = 2,
j = 5;
printf ( "%d^%d = %d\n", i, j, power ( i, j ) );
return ( 0 );
}
/*
* Function to return num^exp
*/
int power ( int num, int exp ) {
int i,
result = 1;
for ( i = 1; i <= exp; ++i )
result *= num;
return ( result );
}
Produces the output
2^5 = 32