#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,r1,r2,rp,ip,disc;
int k;
clrscr();
printf("enter values of abc\n");
scanf("%f%f%f", &a,&b,&c);
if(a==0)
{
printf("value should not be zero\n");
getch();
exit(0);
}
disc=b*b-4*a*c;
if(disc>0)
k=1;
else if(disc==0)
k=0;
else
k=-1;
switch(k)
{
case 1:{
printf("roots are real and unequal\n");
r1=-b+sqrt(disc)/(2*a);
r2=-b-sqrt(disc)/(2*a);
printf("root 1=%.2f\n",r1);
printf("root 2=%.2f\n,r2);
break;
}
case 0:{
printf(roots are real and equal\n");
r1=r2=-b/(2*a);
printf("root 1=%.2f\n",r1);
printf("root 2=%.2f\n,r2);
break;
}
case -1:{
printf(roots are complex\n");
rp=-b/(2*a);
ip=sqrt(-disc)/(2*a);
printf("root 1=%.2f+i*%.2f\n",rp,ip);
printf("root 1=%.2f-i*%.2f\n",rp,ip);
break;
}
getch();
}
c programs