C/C++の宿題を片付けます 54代目
■ このスレッドは過去ログ倉庫に格納されています
0155デフォルトの名無しさん
2005/12/02(金) 22:43:06#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.141592;
double f(double x) {
const double u = 110.9, sigma = 4.7;
return 1.0/sqrt(2*PI)/sigma * exp(-(x-u)*(x-u)/2/sigma/sigma);
}
double F(double a, double b) { // F = integrate[f, {x, a, b}]
const double h = 1e-4;
double S = 0;
for (double x = a; x <= b; x += h)
S += (f(x)+f(x+h))*h/2; // trapezoid integration method:
return S;
}
int main() {
double a, b; cin >> a >> b;
cout << F(a,b) << endl;
}
■ このスレッドは過去ログ倉庫に格納されています