Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- float p,q,r,s,t,u;
- float function(float x){
- float resp=p*exp(x*(-1))+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
- return resp;
- }
- int main() {
- //printf("%f %f %f %f %f %f",&p,&q,&r,&s,&t,&u)
- //cin>>p>>q>>r>>s>>t>>u;
- while(scanf("%f %f %f %f %f %f",&p,&q,&r,&s,&t,&u)!=EOF){
- float ini=0,fin=1,x,resp,encontrado=0;
- if ( ((function(0)>0) && (function(1)>0))|| ((function(0)<0) && (function(1)<0)) ){
- cout << "No solution" << endl;
- continue;
- }
- for (int i=0;i<50;i++){
- x=(fin+ini)/2;
- if (function(x)<0)
- fin=x;
- else
- ini=x;
- }
- printf("%.4f\n",x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment