Home > Programming > Functions using the "C" programming language > example31.c |
/*
In this example we demonstrate the recursive function power.
*/
#include <conio.h>
#include <stdio.h>
/*
Function prototype
*/
float power( float, int );
void main()
{
int i;
for ( i=1; i<10; i++ )
printf("power( 2.0, %d ) = %f.\n", i,
power( 2.0, i ));
getch();
}
float power( float x, int n)
{
if ( n == 1 )
return x;
else
return x * power(
x, n - 1 );
}
© 2004 Jim Valavanis