karlangadas

solve it

Dec 16th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. float p,q,r,s,t,u;
  7. float function(float x){
  8.     float resp=p*exp(x*(-1))+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
  9.     return resp;
  10. }
  11. int main() {
  12.     //printf("%f %f %f %f %f %f",&p,&q,&r,&s,&t,&u)
  13.     //cin>>p>>q>>r>>s>>t>>u;
  14.     while(scanf("%f %f %f %f %f %f",&p,&q,&r,&s,&t,&u)!=EOF){
  15.         float ini=0,fin=1,x,resp,encontrado=0;
  16.         if (   ((function(0)>0) && (function(1)>0))|| ((function(0)<0) && (function(1)<0)) ){
  17.             cout << "No solution" << endl;
  18.             continue;
  19.         }
  20.         for (int i=0;i<50;i++){
  21.             x=(fin+ini)/2;
  22.             if (function(x)<0)
  23.                 fin=x;
  24.             else
  25.                 ini=x;
  26.         }
  27.         printf("%.4f\n",x);
  28.     }
  29.         return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment