前往
大廳
主題

C/C++紀錄二. <<三次多項式找根>> 2018/8/7

艾倫D索妮雅 | 2021-06-07 22:39:46 | 巴幣 0 | 人氣 113

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//版上三次多項式找根//
double f(double x)
{
return pow(x,3)+2*pow(x,2)-4*x-8;
}
int D(double low,double up,double (*fx)(double))
{
return fx(low)*f(up)<=0;
}
int main()
{
const double low=-10.0;
const double up=+10.0;
double x;
for(x=low;x<=up;x+=1.0)
if(D(x,x+1.0,f))
printf("\n>There is one least root at [%+5.2lf,%5.2lf]",x,x+1.0);
system("PAUSE");
system("CLS");
return 0;
}

創作回應

更多創作