Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  we
Language: C/C++
Code:
#include<stdio.h>
#include<math.h>
int main()
{

    int flag;
    float x, x1, x2;
    float a, b, c, d;
    float rpart, ipart;
    

         printf("n Enter 3 numbers: ");
    scanf("%f %f %f", &a, &b, &c);

    if(a==0)

   {

      x=-b/c;
           printf("n Only root x : %7.3f", x);

   }

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

   if(d>0)
       flag=1;

   else if(d==0)
      flag=2;

   else
      flag=3;



   switch(flag)
   {

      case 1:

               printf("n Real & Distinct roots are: ");
          x1=(-b+sqrt(d))/(2*a);
          x2=(-b-sqrt(d))/(2*a);
               printf("n x1=%7.3f n x2=%7.3f", x1, x2);

          break;

      case 2:

               printf("n Repeated roots are: ");
          x1=-b/(2*a);
          x2=x1;
               printf("n x1 & x1 : %7.3f", x1);

          break;

      case 3:

          d=sqrt(abc(d));
          rpart=-b/(2*a);
          ipart=d/(2*a);
               printf("n Complex Roots are: ");
               printf("n x1=%7.3f+i%7.3f", rpart, ipart);
               printf("n x2=%7.3f-i%7.3f", rpart, ipart);

    }

    getchar();

    return 0;

}
          
          
          
          
          
Comments: