#include
<
stdio.h
>
float x1,x2,disc,p,q;
void main()
{
void great_than_zero( float a, float b);
void great_to_zero( float a, float b);
void smaller_than_zero( float a, float b);
float a,b,c;
printf( " input a,b,c: " );
scanf( " %f,%f,%f " , & a, & b, & c);
printf( " equation:%5.2f*x*x+%5.2f*x+%5.2f=0 " ,a,b,c);
disc = b * b - 4 * a * c;
printf( " root: " );
if (disc > 0 )
{
great_than_zero(a,b);
printf( " x1=%f x2=%f " ,x1,x2);
}
else if (disc == 0 )
{
great_to_zero(a,b);
printf( " x1=%f x2=%f " ,x1,x2);
}
else if (disc < 0 )
{
smaller_than_zero(a,b);
printf( " x1=%f+%fi x2=%f-%fi " ,p,q,p,q);
}
}
void great_than_zero( float a, float b)
{
x1 = ( - b + sqrt(disc)) / ( 2 * a);
x2 = ( - b - sqrt(disc)) / ( 2 * a);
}
void great_to_zero( float a, float b)
{
x1 = x2 = ( - b) / ( 2 * a);
}
void smaller_than_zero( float a, float b)
{
p =- b / ( 2 * a);
q = sqrt( - disc) / ( 2 * a);
}
float x1,x2,disc,p,q;
void main()
{
void great_than_zero( float a, float b);
void great_to_zero( float a, float b);
void smaller_than_zero( float a, float b);
float a,b,c;
printf( " input a,b,c: " );
scanf( " %f,%f,%f " , & a, & b, & c);
printf( " equation:%5.2f*x*x+%5.2f*x+%5.2f=0 " ,a,b,c);
disc = b * b - 4 * a * c;
printf( " root: " );
if (disc > 0 )
{
great_than_zero(a,b);
printf( " x1=%f x2=%f " ,x1,x2);
}
else if (disc == 0 )
{
great_to_zero(a,b);
printf( " x1=%f x2=%f " ,x1,x2);
}
else if (disc < 0 )
{
smaller_than_zero(a,b);
printf( " x1=%f+%fi x2=%f-%fi " ,p,q,p,q);
}
}
void great_than_zero( float a, float b)
{
x1 = ( - b + sqrt(disc)) / ( 2 * a);
x2 = ( - b - sqrt(disc)) / ( 2 * a);
}
void great_to_zero( float a, float b)
{
x1 = x2 = ( - b) / ( 2 * a);
}
void smaller_than_zero( float a, float b)
{
p =- b / ( 2 * a);
q = sqrt( - disc) / ( 2 * a);
}