pi와 근사한 프로그램을 작성하려고합니다. 그것은 기본적으로 0.00과 1.00 사이의 무작위 포인트를 가져 와서 원의 경계와 비교합니다. 그리고 원 안에있는 점들의 총점에 대한 비율은 pi에 가까워야합니다 (매우 빠른 설명, 사양은 훨씬 더 깊이있게 들어갑니다). 이 일어나고 무엇C 프로그래밍 - "파일에서 참조 된 정의되지 않은 기호"
Undefined first referenced
symbol in file
pow /var/tmp//cc6gSbfE.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
: GCC로 컴파일 할 때
그러나, 나는 다음과 같은 오류는 무엇입니까? 전에이 오류를 본 적이 없으며 왜 올라 오는지 알지 못합니다. 여기에 내 코드 (I 오류 과거를 얻을 수 없기 때문에 나는 완전히 테스트하지 않았습니다하지만)입니다 : 수학 라이브러리를 포함하는 컴파일 (또는 연결) 동안
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
float x, y;
float coordSquared;
float coordRoot;
float ratio;
int n;
int count;
int i;
printf("Enter number of points: ");
scanf("%d", &n);
srand(time(0));
for (i = 0; i < n; i++) {
x = rand();
y = rand();
coordSquared = pow(x, 2) + pow(y, 2);
coordRoot = pow(coordSquared, 0.5);
if ((x < coordRoot) && (y < coordRoot)) {
count++;
}
}
ratio = count/n;
ratio = ratio * 4;
printf("Pi is approximately %f", ratio);
return 0;
}
그냥'pow (x, 2)'를 사용하지 말고'x * x'를 사용하십시오. 더 빠르고 간단합니다. –