write a program to compute the roots of a quadratic equation A*X^2 + B*X + C = 0. Allow the possibility that (B^2 - 4*A*C) <= 0.
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main( )
{
int A,B,C;
float r1,r2,d;
clrscr( );
printf ("\n Enter the value of the coefficient A:"); scanf ("%d",&A);
printf ("\n Enter the value of the coefficient B:"); scanf ("%d",&B);
printf ("\n Enter the value of the coefficient C:"); scanf ("%d",&C);
printf ("\n The equation is %dX^2+%dX+%d=0",A,B,C);
d=B*B-4*A*C;
if(d<0)
{
printf ("\n Roots of the equation are imaginary.");
}
else
{
r1 = ( -B + sqrt (d) ) / ( 2 * A );
r2 = ( -B - sqrt (d) ) / ( 2 * A );
printf ("\n Roots of the equation are %f and %f",r1,r2);
}
getch( );
}
No comments:
Post a Comment