Friday, March 2, 2012

Roots of a Quadratic Equation

/* A program to find roots of a quadratic equation*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int a,b,c;
float d,r1,r2,x,y;
clrscr();

printf("Enter the values of a,b,c:");
scanf("%d%d%d",&a,&b,&c);

d=b*b-4*a*c;
r1=(-b+sqrt(abs(d)))/(2*a);
r2=(-b-sqrt(abs(d)))/(2*a);
x=-b/(2*a);
y=sqrt(abs(d))/(2*a);

if(d=0)
   printf("The roots are real and equal which is %f.",x);

else if(d>0)
   printf("The roots are real and unequal which are %f and %f.",r1,r2);

else
   printf("The roots are imaginary and unequal which are %f+i%f and %f-iy",x,y,x,y);

getch();
}

No comments:

Post a Comment