#include /* * prototype (forward declaration) */ int power(int m, int n); /* * generate a table of powers of 2 */ void main(void) { register int i; /* counter in a for loop */ /* * generate the table */ for(i = 0; i < 10; ++i) printf("%3d %6d %6d\n", i, power(2, i), power(-3, i)); /* * bye! */ exit(0); } /* * compute a power * * arguments: int base what you want to raise * int n non-negative integral power * to raise base to * * returns: base ^ n (base ** n to you FORTRANers!) * * exceptions: none handled; overflow may occur, but there * will be no indication of it */ int power(int base, int n) { register int i; /* counter in a for loop */ register int p; /* resulting power */ /* * do it the obvious, multiplicative, way */ for(i = 1, p = 1; i <= n; i++) p *= base; return(p); }