2009-06-24 15:54:23 Alan

C++ use IF

#include

#include



#include



using namespace std;



int main(int argc, char *argv[])

{

    //

    //y=f(x)=a*(x^2) + b*(x) + c=0

    double a, b, c, d, x1, x2, y1, y2;

   

    a= 1.0; b= 3.0; c=1.0;

   

    //d= (b^2) - 48a*c

    d= b*b -4.0*a*c;

   

    if (d > 0.0) {

          //

          x1= (-b + sqrt(d))/(2.0*a);

          x2= (-b - sqrt(d))/(2.0*a);

         

          y1= a*(x1*x1) + b*(x1) + c;

          y2= a*(x2*x2) + b*(x2) + c;

         

          printf("x1= %.25lf, y1= %.25lf\n", x1, y1);

          printf("x2= %.25lf, y2= %.25lf\n", x2, y2);

         

         

    }

    else if (d <0.0) {

         //

         printf("d < 0.0, d= %.25lf\n",d);

        

        

    }

    else { // d == 0.0

         //

         printf("d == 0.0, d= %.25lf\n",d);

        

    }

   

    //

    system("PAUSE");

    return EXIT_SUCCESS;

上一篇:C++ Class

下一篇:C++ use SWITCH