Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <math.h>
- using namespace std;
- double determine1(double,double);
- int main()
- {
- double x1,x2,C;
- bool answer=false;
- cout <<"輸入區間端點1:\n";
- cin >> x1;
- cout <<"輸入區間端點2:\n";
- cin >> x2;
- C=determine1(x1,x2);
- if(C>0)
- {
- cout <<"此方程式在此區間無解\n";
- }
- else if (C<0)
- {
- answer = true;
- cout <<"此方程式在此區間有解\n";
- }
- if(answer=true)
- {
- double temp;
- int i;
- for(i=0;i<=1000;i++)
- {
- temp=x1;
- x1=(x1+x2)/2;
- C=determine1(x1,x2);
- if(C>0)
- {
- x2=x1;
- x1=temp;
- }
- }
- cout << "解的近似值為:"<< x1 <<endl;
- }
- system("PAUSE");
- return 0;
- }
- double determine1(double x1,double x2)
- {
- double A,B;
- A=pow(x1,3)+x1-1;
- B=pow(x2,3)+x2-1;
- return A*B;
- }
Add Comment
Please, Sign In to add comment