xmidpnt.c

来自「可以用于科学计算的库」· C语言 代码 · 共 38 行

C
38
字号

/* Driver for routine midpnt */

#include <stdio.h>
#include <math.h>
#define NRANSI
#include "nr.h"

#define NMAX 10

/* Test function */
float func(float x)
{
	return 1.0/sqrt(x);
}

/* Integral of test function */
float fint(float x)
{
	return 2.0*sqrt(x);
}

int main(void)
{
	float a=0.0,b=1.0,s;
	int i;

	printf("\nIntegral of func computed with MIDPNT\n");
	printf("Actual value of integral is %7.4f\n",(fint(b)-fint(a)));
	printf("%6s %29s \n","n","Approx. integral");
	for (i=1;i<=NMAX;i++) {
		s=midpnt(func,a,b,i);
		printf("%6d %24.6f\n",i,s);
	}
	return 0;
}
#undef NRANSI

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?