안녕하세요 테일러급수 sin값 출력 도와주세요 ㅠㅠㅠ
안녕하세요 c언어 완전 초짜에요...
#include
#include
#define PI 3.1415926535897932384626
int Factorial(int num);
int Factorial(int num) {
int result = 1;
int i;
for (i = 1; i <= num; i++)
result *= i;
}
void main()
{
int n, i;
int repeat;
double f;
double x;
double term;
double result;
printf("반복할 횟수를 입력하세요");
scanf_s("%d", &repeat);
for (n = 0; n <= 180; n += 5)
{
x = n * PI / 180;
f = sin(x);
term = x;
result = x;
for (i = 1; i <= repeat; i = i + 1)
{
term = (double)pow(x, (2 * i - 1)) / Factorial(2 * i - 1);
if (i % 2 == 0)
result -= term;
else
result += term;
}
printf("x=%d : sinf(x)=%lf, 근사값 = %lf \n", n, f, result);
}
}
이렇게 꾸역꾸역 썼는데 x가 60넘어가면 갑자기 숫자가 엄청커지면서 이상해져요 ㅠㅠ 도와주시면 정말정말 감사하겠습니다..
repeat 값은 무엇인가요?
repeat 값은 무엇인가요?
댓글 달기