/*-------------------------------------------------------------------*/ /* powerfunction.c */ /*-------------------------------------------------------------------*/ #include /*-------------------------------------------------------------------*/ static int power(int iBase, int iExp) /* Return iBase raised to the iExp power, where iBase and iExp are non-negative. */ { int iPower = 1; int iIndex; for (iIndex = 1; iIndex <= iExp; iIndex++) iPower *= iBase; return iPower; } /*-------------------------------------------------------------------*/ int main(int argc, char *argv[]) /* Read a non-negative base and exponent from stdin. Write base raised to the exponent power to stdout. */ { int iBase; int iExp; int iPower; printf("Enter the base: "); scanf("%d", &iBase); printf("Enter the exponent: "); scanf("%d", &iExp); iPower = power(iBase, iExp); printf("%d to the %d power is %d.\n", iBase, iExp, iPower); return 0; }