Program for Calculating Roots of a Quadratic Equation

# include<stdio.h> #include<conio.h> #include<math.h> main ( ) { int a, b, c, d; float r, r 2 ; printf (“e...

# include<stdio.h>
#include<conio.h>
#include<math.h>
main ( )
{
int a, b, c, d;
float r, r2;
printf (“enter a, b, c values”);
scanf (“%d%d%d”, & a, & b ,& c);
d= b * b – 4 * a * c;
if (d > 0)
{
printf(“ \n roots are real & different”);
r1=(–b + sqrt (d) )/ 2 * a;
r2= (–b – sqrt (d)) / 2 * a;
printf (“\n roots r1= % f \t r2= % f “ ,r1,r2);
}
if (d = = 0)
{
printf(“\n roots are real and same”);
r1=-b/(2*a);
r2=r1;
printf ("\n roots r1=% f \t r2= % f”, r1,r2);
}
else
printf (“\n roots are imaginary”);
getch ( ) ;
}

Out Put:

enter a,b,c values 2 3 5
roots are imaginary

enter a,b,c values 1 2 1
roots are real and same
r1=-1.0000     r2=-1.0000


Related

C Programs 858075609866533458

Post a Comment

emo-but-icon

item