Next: ptr_arr.c Up: Program Listings Previous: factorial

power.c


#include <stdio.h>

int     power (int m, int n);

main () {
    int     i;

    printf ("power\t   2^power\t -3^power\n");
    for (i = 0; i < 10; ++i)
	printf ("%5d \t%8d \t%8d\n", i, power (2, i), power (-3, i));
    return 0;
}

int     power (int base, int n) {
    int     i,
            p;
    p = 1;
    for (i = 1; i <= n; ++i)
	p *= base;
    return p;
}


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994