[C言語]正接(tangent)

sine, cosine, tangentを日本語で、正弦、余弦、正接という
tanは45°で1, 30°で√3/3

#include 
#include 


int main(void){

	int thd;
	double th;
	FILE *fp = NULL;
	char c[128];

	fp=fopen("tangent.txt", "w");
	if(fp == NULL) return 1;
	fputs("正接表\n\n", fp);

	fputs("角度\t正接\n",fp);
	printf("\n角度\t正接\n");

	for(thd=-89; thd<90; thd+=1){
		th = thd*0.017453295;
		sprintf(c, "%3d\t%10.6f\n",thd, tan(th));
		fputs(c,fp);
		printf("%s",c);
	}
	if(fp!=NULL) fclose(fp);

	return 0;
}

$ gcc -o main main.c
/tmp/cc1hB26c.o: In function `main':
main.c:(.text+0xe1): undefined reference to `tan'

あれ? tanは特にincludeは要らないはずだが。
stackoverflowに買いてありますな。

You should add -lm to your compiler option.
Besides of that, you could also change -lpthread to -pthread.

$ gcc -o main main.c -lm
$ ./main

角度 正接
-89 -57.290686
-88 -28.636432
-87 -19.081215
-86 -14.300710
-85 -11.430080
-84 -9.514384
-83 -8.144360
-82 -7.115380
-81 -6.313760
-80 -5.671288
-79 -5.144559
-78 -4.704635
-77 -4.331480
-76 -4.010784
-75 -3.732054
-74 -3.487417
-73 -3.270855
-72 -3.077685
-71 -2.904213
-70 -2.747479
-69 -2.605090
-68 -2.475088
-67 -2.355853
-66 -2.246038
-65 -2.144508
-64 -2.050305
-63 -1.962611
-62 -1.880727
-61 -1.804048
-60 -1.732051
-59 -1.664280
-58 -1.600335
-57 -1.539865
-56 -1.482561
-55 -1.428148
-54 -1.376382
-53 -1.327045
-52 -1.279942
-51 -1.234897
-50 -1.191754
-49 -1.150369
-48 -1.110613
-47 -1.072369
-46 -1.035531
-45 -1.000000
-44 -0.965689
-43 -0.932515
-42 -0.900404
-41 -0.869287
-40 -0.839100
-39 -0.809784
-38 -0.781286
-37 -0.753554
-36 -0.726543
-35 -0.700208
-34 -0.674509
-33 -0.649408
-32 -0.624869
-31 -0.600861
-30 -0.577350
-29 -0.554309
-28 -0.531710
-27 -0.509526
-26 -0.487733
-25 -0.466308
-24 -0.445229
-23 -0.424475
-22 -0.404026
-21 -0.383864
-20 -0.363970
-19 -0.344328
-18 -0.324920
-17 -0.305731
-16 -0.286745
-15 -0.267949
-14 -0.249328
-13 -0.230868
-12 -0.212557
-11 -0.194380
-10 -0.176327
-9 -0.158384
-8 -0.140541
-7 -0.122785
-6 -0.105104
-5 -0.087489
-4 -0.069927
-3 -0.052408
-2 -0.034921
-1 -0.017455
0 0.000000
1 0.017455
2 0.034921
3 0.052408
4 0.069927
5 0.087489
6 0.105104
7 0.122785
8 0.140541
9 0.158384
10 0.176327
11 0.194380
12 0.212557
13 0.230868
14 0.249328
15 0.267949
16 0.286745
17 0.305731
18 0.324920
19 0.344328
20 0.363970
21 0.383864
22 0.404026
23 0.424475
24 0.445229
25 0.466308
26 0.487733
27 0.509526
28 0.531710
29 0.554309
30 0.577350
31 0.600861
32 0.624869
33 0.649408
34 0.674509
35 0.700208
36 0.726543
37 0.753554
38 0.781286
39 0.809784
40 0.839100
41 0.869287
42 0.900404
43 0.932515
44 0.965689
45 1.000000
46 1.035531
47 1.072369
48 1.110613
49 1.150369
50 1.191754
51 1.234897
52 1.279942
53 1.327045
54 1.376382
55 1.428148
56 1.482561
57 1.539865
58 1.600335
59 1.664280
60 1.732051
61 1.804048
62 1.880727
63 1.962611
64 2.050305
65 2.144508
66 2.246038
67 2.355853
68 2.475088
69 2.605090
70 2.747479
71 2.904213
72 3.077685
73 3.270855
74 3.487417
75 3.732054
76 4.010784
77 4.331480
78 4.704635
79 5.144559
80 5.671288
81 6.313760
82 7.115380
83 8.144360
84 9.514384
85 11.430080
86 14.300710
87 19.081215
88 28.636432
89 57.290686