1030
20154835117
at 2018-03-13T13:00:18+00:00
<!--Markdown-->
#include<stdio.h>
#include<math.h>
int main(void)
{
float a,b,c,x,l,x1,x2,s;
int L,S;
scanf("%f %f %f",&a,&b,&c);
x=pow(b,2)-4*a*c;
x1=((-1)*b+sqrt(x))/(2*a);
x2=((-1)*b-sqrt(x))/(2*a);
l=x1-int(x1);
if(l==0)
L=0;
else
L=1;
s=x2-int(x2);
if(s==0)
S=0;
else
S=1;
if(x>0)
{
switch(L)
{
case 0:
printf("The roots are %.f ",x1);
break;
case 1:
printf("The roots are %.6f ",x1);
break;
}
switch(S)
{
case 0:
printf("and %.f",x2);
break;
case 1:
printf("and %.6f",x2);
break;
}
}
else if(x==0)
{
switch(L)
{
case 0:
printf("The root is %.f",x1);
break;
case 1:
printf("The root is %.6f",x1);
break;
}
}
else
printf("The equation has no real roots");
return 0;
}
Comments: