Roots of Quadratic Equation

Problem Statement
Write a c programme to find root of a quadratic equation
consider all the cases

#include<stdio.h>
#include<math.h>
int main()
{
  float  a,b,c,discr,root1,root2;
  printf("enter the value of a,b,c \n");
  scanf("%f %f %f",&a, &b,&c);
  if(a!=0)
    {
      discr=( (b*b)-(4*a*c));
      if(discr<0)
{
 printf("the roots of the equation are imaginary \n");
}
      else
        {
 if(discr==0)
   {
     printf("there is only one root of thye equation which is %f", (b/(-a*2)));
   }
 else
   {
     discr=sqrt(discr);
     root1= (-b+discr)/(2*a);
     root2= (-b-discr)/(2*a);
     printf("the roots are %f and %f \n",root1,root2);
   }
        }    
      
    }
  else
    {
      printf("the given equation is not a quadratic its root is %f",(-c/b));
    }
  
  return 0;


No comments:

Post a Comment