I am trying to write a recursive function that compute a to the n.
here is as far as I have gotten as far as code
#include "stdafx.h"
#include "stdio.h"
int power (int n); // function prototype//
main()
{
float a;
int n;
printf("\n enter values of a an n");
printf("\n %.4f to the power of % d is %.4f",a,n,power(a,n));
}
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));
}
}
I have 2 errors
cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\owner\my documents\visual studio 2008\projects\lab 8.3.1\lab 8.3.1\lab 8.3.1.cpp(19) : error C2660: 'power' : function does not take 2 arguments