#include <stdio.h>
#include <math.h>
double f(double x){
return (x*x);
}
double integrateF(double (function)(double) ){
double area;
double x_width;
int k; // Counter necessary for For-Loop
int n; // # of bars
double min; // Limit min
double max; // Limit max
printf("Please enter the limit minima, 'a'==>\n");
scanf("%lf",&min);
printf("Please enter the limit maxima, 'b'==>\n");
scanf("%lf",&max);
printf("Please enter # of bars needed to span [a,b]==>\n");
scanf("%d",&n);
x_width=(max-min)/n;
for(k=1;k<=n;k++){
area+=function(min+x_width*(k-0.5));
}
area*=x_width;
return area;
}
int main(void){
double resultant;
resultant=integrateF(f);
printf("The value of the integral is: %f \n",resultant);
return 0;
}
すべての夕方、
私の最初のモジュールは、関数 (x^2) で構成されています。戻り値は、integrateF(f) に進み、2 番目のモジュールを初期化します。これは物事が混乱するときです...
この行は何をしますか?
double integrateF(double (関数)(double) ){
重要な注意: 私のプログラムはスムーズに実行されますが、この行が原因で理由がわかりません。
このコードを改造して最初のモジュールとこの奇妙な行を除外する方法はありますか (そして、必要なものは何でも同様に実行できます)、(x^2) 関数をネストする統合モジュールしかありません。
もちろん、私のメイン(無効)モジュールはそのままです。