Roots of a Quadratic Equation

/* The Program By Tittu Varghese */

// Roots of a Quadratic Equation



#include<stdio.h>

#include<math.h>
#include<conio.h>

void main()

{

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

printf("Enter the Value of a , b and c");

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



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


if (d < 0)

  { r1 = (-b)/(2*a);
    r2 = (sqrt(-1*d))/ (2*a);
    printf("The Roots are Imaginary\n");
    printf("R1 is %f+i%f\n",r1,r2);
    printf("R2 is %f-i%f",r1,r2);

else if (d == 0)

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

      printf("The roots are equal and R is %f",r);

      

        else

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

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

               printf("The roots are real and r1 is %f and r2 is %f",r1,r2);

             }
getch();
}





//**sqrt" is used to find square root of a number.sqrt function is in math.h header.**
//here getch() is used to hold the output.

Comments

Popular posts from this blog

Algorithm to display "n" natural numbers #c

Algorithm to display the sum of n natural numbers #c

Algorithm for Sum of two numbers