im intending to do a function that'll calculate the cosine of x like this:
1-x^2/2! + x^4/4! - x^6/6! ...
and compiler says that it doesn't support "%lf" format and "undefined" to pow and cos ? why
#include <stdio.h>
#include <math.h>
double my_cos(double c){
int i,k;
double result=1.0;
for(i=1; i<10; i++){
k= (i%2==0)?1:-1;
result+= (k*pow(i,c))/factorial(i);
}
return result;
}
int main (){
double c;
printf("Enter the radian degree:\n");
scanf("%lf",&c);
printf(" my_cos : %lf\n cos: %lf\n", my_cos(c), cos(c));
return 0;
}
the compiler's Errors:
gcc -c -Wall -ansi -pedantic -lm my_cos.c -o my_cos.o
my_cos.c: In function ‘main’:
my_cos.c:28:3: warning: ISO C90 does not support the ‘%lf’ gnu_printf format [-Wformat]
my_cos.c:28:3: warning: ISO C90 does not support the ‘%lf’ gnu_printf format [-Wformat]
gcc -g -Wall -ansi -pedantic -lm my_cos.o -o my_cos
my_cos.o: In function my_cos': my_cos.c:(.text+0x8a): undefined reference to
pow'
my_cos.o: In function main': my_cos.c:(.text+0xef): undefined reference to
cos'
collect2: ld returned 1 exit status
make: *** [my_cos] Error 1