写在前面:最近切了新的ide
(一).
(2x+3)dx
//============================================================================
// Name : LowOrderDefiniteIntegral.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : (2x+3)dx|[0,1] in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
float func(float x){
return 2*x+3;
}
float ING(float a,float b){
return (b-a)/2*(func(a)+func(b));
}
int main() {
float a,b;
cin>>a>>b;
cout<<ING(a,b)<<endl;
return 0;
}
运行效果:

?
(二).
? ( +2x-1)dx
#include <iostream>
#include <math.h>
using namespace std;
float func(float x){
return pow(x,3)+2*x-1;
}
float ING(float a,float b){
return ((b-a)/6)*(func(a)+4*func((a+b)/2)+func(b));
}
int main() {
float a,b;
cin>>a>>b;
cout << ING(a,b)<<endl;
return 0;
}
Run:

?
|