#include<iostream>#include<math.h>usingnamespace std;intmain(){int k;double m, n;double i, sum;double eps =1e-6;double a, b, c, d;double f1, f2;double* p=&i;
cout <<"求解形如ax^3+bx^2+cx+d=0方程请输入1\n求解形如asin(x)+bx=0输入2"<< endl;
cin >> k;if(k ==1){
cout <<"输入a,b,c,d"<< endl;
cin >> a >> b >> c >> d;
cout <<"输入m,n"<< endl;
cin >> m >> n;
f1 = a *pow(m,3)+ b *pow(m,2)+ c * m + d;
f2 = a *pow(n,3)+ b *pow(n,2)+ c * n + d;if(f1 * f2 <0){while(fabs(m - n)> eps){
i =(m + n)/2;
sum = a *pow(i,3)+ b *pow(i,2)+ c * i + d;if(fabs(sum)< eps){
cout <<"该方程的近似解"<<*p;break;}elseif(sum * f2 <0){
m =*p;}elseif(f1 * sum <0){
n =*p;}}}else{
cout <<"该区间内无解!";}}else{
cout <<"输入a,b"<< endl;
cin >> a >> b;
cout <<"输入m,n"<< endl;
cin >> m >> n;
f1 = a *sin(m)+ b *m ;
f2 = a *sin(n)+ b * n ;if(f1 * f2 <0){while(fabs(m - n)> eps){
i =(m + n)/2;
sum = a *sin(i)+ b * i;if(fabs(sum)< eps){
cout <<"该方程的近似解"<<*p;break;}elseif(sum * f2 <0){
m =*p;}elseif(f1 * sum <0){
n =*p;}}}else{
cout <<"该区间内无解!";}}return0;}