#include <stdio.h>
#include <math.h>
void shigen(int,int,int);
void denggen(int,int,int);
void xugen(int,int,int);
int main(int argc, int *argv[])
{
int a,b,c;
float gen;
printf("input a,b,c:");
scanf("%d,%d,%d",&a,&b,&c);
printf("\n");
gen = b * b - 4 * a * c;
if (gen > 0)
{
shigen(a,b,gen);
}
else if (gen == 0)
{
denggen(a,b,gen);
}
else
{
xugen(a,b,gen);
}
system("pause");
return 0;
}
void shigen(int a, int b,int sqrt_value)
{
float x1,x2;
x1 = (-1 * b + sqrt(sqrt_value))/(2 * a);
x2 = (-1 * b - sqrt(sqrt_value))/(2 * a);
printf("x1 = %f,x2 = %f\n",x1,x2);
}
void denggen(int a, int b, int sqrt_value)
{
float x1;
x1 = (-1 * b) / (2 * a);
printf("x1 = x2 = %f",x1);
}
void xugen(int a, int b, int sqrt_value)
{
float x1,x2;
x1 = (-1 * b) / (2 * a);
x2 = sqrt(-1 * sqrt_value) / (2 * a);
printf("xugen x1 = %.3f + %.3fi ,x2 = %.3f - %.3fi",x1,x2,x1,x2);
}
|