#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,r,d,r1,r2,im;
clrscr();
printf("\n\tQuadrtic Eqution\n\nEnter the cofficents\n");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
r=b/2*a;
if(d>0)
{
r1=-r+(sqrt(d)/2*a);
r2=-r-(sqrt(d)/2*a);
printf("\nRoots are real and distinct\n\nfirst root\t: %.2f\n\nsecound root\t: %.2f\n",r1,r2);
}
else if(d==0)
{
printf("\nRoots are real and equal\n\nroots= %.2f",-r);
}
else
{
d=-d;
im=sqrt(d)/2*a;
printf("\nRoots are imaginary\n\nfirst root\t; %.2f+i%.2f\n\nsecound root\t: %.2f-i%.2f",r,im,r,im);
}
getch();
}
Algorithm
step 1: Start
step 2: Read a,b,c
step 3: intilize d<-(b*b)-(4*a*c)
step 4: intilize r<-b/2*a
step 5: if d>0 go to step 6
else go to step8
step 6: r1=r+(sqrt(d)/2*a) and r2=r-(sqrt(d)/2*a)
step 7: print roots are real and distinct ,first root r1,second root r2
step 8: if d=0 go to step9
else go to step10
step 9: print roots are real and equal,-r
step 10: d=-d
step 11: im=sqrt(d)/2*a
step 12: print roots are imaginary ,first root r+i im,second root r-i im
step 13: stop