作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,这是我到目前为止所拥有的:
#include <stdio.h>
#include <math.h>
//#define PI 3.14159
int factorial(int n){
if(n <= 1)
return(1);
else
return(n * factorial(n-1));
}
void McLaurin(float pi){
int factorial(int);
float x = 42*pi/180;
int i, val=0, sign;
for(i=1, sign=-1; i<11; i+=2){
sign *= -1; // alternate sign of cos(0) which is 1
val += (sign*(pow(x, i)) / factorial(i));
}
printf("\nMcLaurin of 42 = %d\n", val);
}
void Taylor(float pi){
int factorial(int);
float x;
int i;
float val=0.00, sign;
float a = pi/3;
printf("Enter x in degrees:\n");
scanf("%f", &x);
x=x*pi/180.0;
printf("%f",x);
for(i=0, sign=-1.0; i<2; i++){
if(i%2==1)
sign *= -1.0; // alternate sign of cos(0) which is 1
printf("%f",sign);
if(i%2==1)
val += (sign*sin(a)*(pow(x-a, i)) / factorial(i));
else
val += (sign*cos(a)*(pow(x-a, i)) / factorial(i));
printf("%d",factorial(i));
}
printf("\nTaylor of sin(%g degrees) = %d\n", (x*180.0)/pi, val);
}
main(){
float pi=3.14159;
void McLaurin(float);
void Taylor(float);
McLaurin(pi);
Taylor(pi);
}
McLaurin of 42 = 0
Enter x in degrees:
42
0.733038-1.00000011.0000001
Taylor of sin(42 degrees) = -1073741824
#include <stdio.h>
#include <math.h>
//#define PI 3.14159
int factorial(int n){
if(n <= 1)
return(1);
else
return(n * factorial(n-1));
}
void McLaurin(float pi){
int factorial(int);
float x = 42*pi/180, val=0;
int i, sign;
for(i=1, sign=-1; i<11; i+=2){
sign *= -1; // alternate sign of cos(0) which is 1
val += (sign*(pow(x, i)) / factorial(i));
}
printf("\nMcLaurin of of sin(%f degrees) = %f\n", (x*180.0)/pi, val);
}
void Taylor(float pi){
int factorial(int);
float x;
int i;
float val=0, sign;
float a = pi/3;
printf("Enter x in degrees:\n");
scanf("%f", &x);
x=x*pi/180.0;
printf("%f",x);
for(i=0, sign=-1.0; i<2; i++){
if(i%2==0)
sign *= -1; // alternate sign of cos(0) which is 1
printf("%f",sign);
if(i%2==0)
val += (sign*sin(a)*(pow(x-a, i)) / factorial(i));
else
val += (sign*cos(a)*(pow(x-a, i)) / factorial(i));
printf("%d",factorial(i));
}
printf("\nTaylor of sin(%f degrees) = %f\n", (x*180.0)/pi, val);
}
main(){
float pi=3.14159;
void McLaurin(float);
void Taylor(float);
McLaurin(pi);
Taylor(pi);
}
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot open output file a.exe: Device or resource busy
collect2: ld returned 1 exit status
Can anyone explain what's wrong now?
最佳答案
一些潜在的错误来源:
关于c - 需要麦克劳林级数和泰勒级数的编程帮助吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2923811/
考虑函数 y=1/((1-x^5)(1-x^7)(1-x^11)) WolframAlpha 在几秒钟内计算出 MacLaurin 级数展开的前 1000 个元素: https://www.wolfr
我是一名优秀的程序员,十分优秀!