?? repeat_t.cpp
字號:
/////////////////////////////////////////////////////////////////
// §3 數值積分
//
// 程序3.1 — 復化T型公式
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include "expressi.cpp"
// 積分區間[a,b], 被積函數 f(x) = FxString, 等份數 n
float RepeatT( char FxString[], float a, float b, int n )
{
int i;
float h, Value;
if( n <= 0) return 0;
h = ( b - a ) / n;
if( CreateFx( FxString ) ) return 0; // 建立f(x)
Value = 0;
for( i = 1; i < n; ++i )
{
Value += f( a + i * h );
}
return( ( f(a) + f(b) + 2 * Value ) * h / 2 );
}
void main()
{
float i1,a,b;
int n;
char FxString[200];
printf( "\nInput function, a, b, n: " );
scanf( "%s %f %f %d", FxString, &a, &b, &n );
i1 = RepeatT(FxString,a,b,n);
printf( "\n%f", i1 );
getch( );
}
/*
運行實例:
Input function,a,b,n: 1/(1+x) 0 1 10
0.693771
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -