可能重复:
获取 sin() 的值时出现 C 构建错误
我正在尝试在该期间使用 100 个间隔来集成一个函数,所以我使用了一个 for 循环。该函数包含 cos(stuff here),但由于某种原因它不会在 for 循环中运行。如果我将它移出 for 循环,它工作正常。我有 #include ,所以我不明白。任何帮助表示赞赏。谢谢。
#include <stdio.h>
#include <math.h>
//float t = 0.000000;
double T = .001;
int n = 100;
double pi = 3.141592654;
double a[5];
double b[5];
double function_results[100];
double anfunction_results[100];
double bnfunction_results[100];
double final = 0.000000000000;
double anfinal = 0.000000000;
double k = 0.000000;
double function(float t){
double f = 3*pow(t,2);
return f;
}
int main()
{
//double w = 2*pi/T;
double h = T/n;
int i = 1;
for(; i<100; i++){
double iterate = -T/2 + h*i;
function_results[i] = function(iterate);
final = final + function_results[i];
}
a[0] = (h/3)*(function(-T/2) + final+function(T/2))/T;
printf("%.12f \n",a[0]);
int p = 1;
int l = 1;
for(; l<=5; l++){
for(; p<100; p++){
double iteration = -T/2 + h*p;
k = l+.0000001;
anfunction_results[p] = 3*pow(iteration,2)*cos(k*iteration*2.00000*pi/T*pi/180.00000);
anfinal = anfunction_results[p] + anfinal;
}
a[l] = (2/T)*(h/3)*(3*pow(-T/2,2)*cos(-T/2.0000) + anfinal + 3*pow(T/2,2)*cos(k*T/2.00000*2.00000*pi/T*pi/180.00000));
}
//printf("%.12f \n",a[1]);
//printf("%.12f \n",a[2]);
//printf("%.12f \n",a[3]);
//printf("%.12f \n",a[4]);
//printf("%.12f \n",a[5]);
return 0;
}