Hello!
I have been working on this for several days now and the program has no errors but it does not calculate. Here's the code:
Code:
#include "stdafx.h"
#include "stdio.h"
float power(float a, int n); // function prototype//
int main (void)
{
float a;
int n;
printf("\n enter a value of a");
scanf ("%f", &a);
printf("\n enter value of n");
scanf ("%f", &n);
printf("\n %.4f to the power of % d is %.4f",a,n,power(a,n));
return 0;
}
float power(float a, int n)
{
if (a==0)
{
return 0;
}
else if(n==0)
{
return 1;
}
else if (n>0)
{
return( a* power(a,n-1));
}
else
{
return ((1/a)*power(a,n+1));
}
}
Please help me figure this out!