/*
Program demonstrating Power Function
*/
#include<stdio.h>
#include<conio.h>
//Power Function Integer Version
int power(int base, int exponent)
{
int i;
int result = 1;
for(i=1; i<=exponent; i++)
{
result = result * base;
}
return result;
}
//Power Function Floating-Point Version
float powerfloat(float base, float exponent)
{
float i;
float result = 1.0;
for(i=1; i<=exponent; i++)
{
result = result * base;
}
return result;
}
int main()
{
int a, b, c;
a=2;
b=3;
printf(“\n ~~~Power Functions C~~~ \n”);
printf(“\n %d to the power %d is %d”, a,b, power(a,b));
printf(“\n 2.0 to the power 4.0 is %f”, powerfloat(2.0, 4.0));
getch();
return 0;
}
Snapshot of the o/p
