Thursday, October 30, 2025

Enter Coefficient of Quadratic Equations. Find the Properties of Equation.

#include<stdio.h>
#include<math.h>
main()
{
   float a,b,c;
   float d,r1,r2;
   /* 1 3 8        0 5 8       2 4 2     3 8 2 */
   printf("\n Enter the Values of A B C: ") ;
   scanf("%f%f%f", &a,&b,&c) ;
   d = b * b - 4 * a * c;
   if(a != 0)
   {
      if(d < 0)
      {
         r1=-b/(2*a);
         r2= sqrt(-d)/(2*a);
    printf("\n Roots are Complex/Imaginary.\n");
         printf("\n Root1 = %.3f%+.3fi",r1,r2);
         printf("\n Root2 = %.3f%+.3fi",r1,-r2);
      }
      else
      if(d==0)
      {
    printf("\n Both Roots are Real and Equal.\n");
    r1 = -b /(2* a);
    printf("\n Root1 = %.3f ",r1);
         printf("\n Root2 = %.3f ",r1);
      }
      else
      if(d > 0)
      {
    printf("\n Roots are Real  and Unequal.\n");
    r1 = ( -b + sqrt(d)) / (2* a);
    r2 = ( -b - sqrt(d)) / (2* a);
    printf("\n Root1 = %.3f , Root2 = %.3f",r1,r2);
      }
    }
    else
       printf("\n Equation is linear.");
}





No comments:

Post a Comment