Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Program to find the roots of quadratic equation (Demonstration of else-if ladder)

 Program to find the roots of quadratic equation (Demonstration of else-if ladder)


#include<stdio.h>

#include<math.h>

void main ()

{

   float a,b,c,r1,r2,d;

   printf ("enter the values of a b c\n");

   scanf ("%f%f%f",&a,&b,&c);

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

   if (d>0)

   {

      r1 = -b+sqrt (d) / (2*a);

      r2 = -b-sqrt (d) / (2*a);

      printf ("The real roots = %f %f", r1, r2);

   }

   else if (d==0){

      r1 = -b/(2*a);

      r2 = -b/(2*a);

      printf ("roots are equal =%f %f", r1, r2);

   }

   else

      printf("Roots are imaginary");

  

}

Post a Comment

0 Comments