⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 用截弦法求方程的根.cpp

📁 验证歌德巴赫猜想等
💻 CPP
字号:
/*用截弦法求方程的根*/
#include<stdio.h>
#include<math.h>
float f(float );
float xpoint(float ,float );
float root(float ,float );

void main()
{
	float x1,x2,f1,f2,x;
	do
	{
		printf("input x1,x2:\n");
		scanf("%f%f",&x1,&x2);
		f1=f(x1);
		f2=f(x2);
	}
     while (f1*f2>=0);
	 x=root(x1,x2);
	 printf("A root of equation is %7.2f",x);
}

float f(float x)
{
	return ((x-5.0)*x+16.0 )*x-80.0;
}

float xpoint(float x1,float x2)
{
	return (x1*f(x2)-x2*f(x1))/( f(x2)-f(x1) );
}

float root(float x1,float x2)
{
	int i;float x,y,y1;
	y1=f(x1);
	do
	{
		x=xpoint(x1,x2);
		y=f(x );
		if(y*y1>0)
		{
			y1=y;x1=x;
		}
		else
			x2=x;
	}
	while(fabs(y )>=0.0001);
		return(x);
}

⌨️ 快捷键说明

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