power function in c without pow
// power function in c without pow
#include <stdio.h>
double mypow(double base, double power);
int main()
{
int base, exponent;
printf("Enter Base: ");
scanf("%d", &base);
printf("Enter Exponent: ");
scanf("%d", &exponent);
printf("%d raised to the power %d = %0.2lf\n", base, exponent, mypow(base, exponent));
return 0;
}
double mypow(double base, double power)
{
double result = 1;
if (power >= 0)
{
while (power--)
{
result = result * base;
}
return result;
}
else if (power < 0)
{
while (power++)
{
result = result * base;
}
return 1 / result;
}
}