/*the solution oif equations */
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, c;
double delta;
double x1, x2;
char ch;
do
{
printf("请输入方程的三个参数:\n");
printf("a = ");
scanf("%lf", &a);
printf("b = ");
scanf("%lf", &b);
printf("c = ");
scanf("%lf", &c);
delta = b*b - 4*a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("方程有两个实数根:\n\n");
printf("x1 = %lf , x2 = %lf\n\n", x1, x2);
}
else if (delta == 0)
{
x1 = -b / (2*a);
printf("方程只有一个实数根:\n\n");
printf("x1 = x2 = %lf\n\n", x1);
}
else
printf("方程无实数根 !\n\n");
printf("想继续吗? Y/N ");
scanf(" %c", &ch);
printf("\n");
}while ('y' == ch || 'Y' == ch);
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, c;
double delta;
double x1, x2;
char ch;
do
{
printf("请输入方程的三个参数:\n");
printf("a = ");
scanf("%lf", &a);
printf("b = ");
scanf("%lf", &b);
printf("c = ");
scanf("%lf", &c);
delta = b*b - 4*a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("方程有两个实数根:\n\n");
printf("x1 = %lf , x2 = %lf\n\n", x1, x2);
}
else if (delta == 0)
{
x1 = -b / (2*a);
printf("方程只有一个实数根:\n\n");
printf("x1 = x2 = %lf\n\n", x1);
}
else
printf("方程无实数根 !\n\n");
printf("想继续吗? Y/N ");
scanf(" %c", &ch);
printf("\n");
}while ('y' == ch || 'Y' == ch);
return 0;
}