一元二次方程求根c语言编程,一元二次方程求解程序完整代码

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

下面的代码是我刚才无聊写的。对于简单的一元多次方程的迭代

#include

#include

#include

#define MAXTIMES 5

typedef int times;

typedef double coefficient;

typedef struct _properties

{

coefficient x; //系数

times n;//次数

}properties; typedef properties equation_expression ;

equation_expression equ[MAXTIMES];

double diff(double x)

{

double ds = 0.0 ;

for(int i = 0 ;i< MAXTIMES ;i++)

{

if(equ[i].n ==0 )

continue;

else{

double xn = 1.0;

for(int j =0 ;j

xn *= x;

ds += equ[i].x *equ[i].n* xn;

}

}

return ds;

}

double equvalue(double x)

{

double ds = 0.0 ;

for(int i = 0 ;i< MAXTIMES ;i++)

{

if(equ[i].n ==0 )

ds += equ[i].x;

else

{

double xn = 1.0;

for(int j =0 ;j

xn *= x;

ds += xn * equ[i].x;

}

}

return ds;

}

//

void buildequfunction()

{

printf("input data like this a ,b a is coefficient b is times of equation\n");

//sorry dont realize; this time just do ax^2+ bx +c = 0

equ[0].x = 2.0;

equ[0].n = 2;

equ[1].x = 7.0;

equ[1].n = 1;

equ[2].x = 3.0;

equ[2].n = 0;

equ[3].x = 3.0;

equ[3].n = 3;

//this 3*x^3 +2x^2 + 7x +3 = 0

}

int main (void) {

memset(equ,0,sizeof(equ));

buildequfunction();

double error_control = 0.0000000001 ;

double _begin, _end ;

//so you should give a data to begin the game.and some times it will not work.

scanf("%lf",&_begin);

do{

_end = _begin - equvalue(_begin)/diff(_begin);

}while( (fabs(_end -_begin)> error_control)&& (_begin = _end));

printf("one %lf \n",_end);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值