#include <stdio.h>
#include <math.h>
float mysqrt (float x)
{
float y;
x=x-1;
y= 1+(x/2)-(pow(x,2)/2)+(pow(x,3)/8)-(5*pow(x,4)/128);
return y;
}
int main()
{
printf("%f",mysqrt(5));
}
I searched older answer in this website and tried to use them but still I cant figure out why it doesnt work
I don't think the code you have posted is quite accurate.
You are probably calling mysqrt()
before you have provided a declaration of the function. In old versions of the C standard (C89), this was allowed and the function would be given an implicit declaration of:
int mysqrt();
That is, a function taking an unknown number of non-variadic parameters, and returning int. This clearly contradicts the actual definition of the function.
In more recent versions of the standard (C99/C11), the compiler is required to produce a diagnostic message if you try to call a function that has not been declared.
You should change your code so that the function definition appears before the function call, or provide a function declaration before the function call. Eg:
float mysqrt (float);
int main()
{
printf("%f",mysqrt(5));
}
float mysqrt (float x)
{
/* Function body */
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments