Uva 10341 Solution

#include<bits/stdc++.h>
using namespace std;
double p, q, r, s, t, u;
double anik(double x)
{
    double d = (p * exp(-x))+ (q*sin(x)) + (r*cos(x)) + (s*tan(x)) + (t*x*x) + u;
    return d;
}
int main()
{
    int i;
    while(cin >> p >> q >> r >> s >> t >> u)
    {
        double a = 0.0, b = 1.0, x = 0, y = 0;
        x = anik(a), y = anik(b);
        if(x*y>0)
        {
            cout << "No solution" << "\n";
        }
        else
        {
            double c = 0;
            for(i=1; i<=30; i++)
            {
                c = (a+b)/2;
                double d = anik(c);
                if(d > 0)
                    a = c;
                else if(d <= 0)
                    b = c;
            }
            cout << showpoint;
            cout << fixed;
            cout << setprecision(4);
            cout << c << "\n";
        }
    }

    return 0;
}

Comments