用C语言求二元一次方程的根
4个回答
展开全部
# include <stdio.h>
# include <math.h>
int main(void)
{
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("有两个解,x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (0 == delta)
{
x1 = x2 = (-b) / (2*a);
printf("有唯一解,x1 = x2 = %lf\n", x1, x2);
}
else
{
printf("无实数解!\n");
}
printf("您想继续么(Y/N): ");
scanf(" %c", &ch); //%c前面必须得加一个空格 原因略
} while ('y'==ch || 'Y'==ch);
return 0;
}
希望可以帮到你,如果满意请采纳!
# include <math.h>
int main(void)
{
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("有两个解,x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (0 == delta)
{
x1 = x2 = (-b) / (2*a);
printf("有唯一解,x1 = x2 = %lf\n", x1, x2);
}
else
{
printf("无实数解!\n");
}
printf("您想继续么(Y/N): ");
scanf(" %c", &ch); //%c前面必须得加一个空格 原因略
} while ('y'==ch || 'Y'==ch);
return 0;
}
希望可以帮到你,如果满意请采纳!
展开全部
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main(void)
{
double a,b,c,d,e,f;
printf("请输入: a,b,c:");
scanf("%lf %lf %lf",&a,&b,&c);
d=b*b-4*a*c;
if( 0 == a )
{
if( 0 == b )
{
if( 0 == c )
{
printf("参数都为零,方程无意义\n");
}
else
{
printf("ab都为零,c不为零,方程不成立\n");
}
}
else
{
printf("x=%lf\n",-c/b);
}
}
else if( d>=0 )
{
printf("x1=%lf\n",(-b+sqrt(d))/(2*a));
printf("x2=%lf\n",(-b-sqrt(d))/(2*a));
}
else
{
printf("x1=%lf+%lf\n",-b/(2*a),sqrt(-d)/(2*a));
printf("x2=%lf-%lf\n",-b/(2*a),sqrt(-d)/(2*a));
}
getch();
return 0;
}
#include <conio.h>
#include <math.h>
int main(void)
{
double a,b,c,d,e,f;
printf("请输入: a,b,c:");
scanf("%lf %lf %lf",&a,&b,&c);
d=b*b-4*a*c;
if( 0 == a )
{
if( 0 == b )
{
if( 0 == c )
{
printf("参数都为零,方程无意义\n");
}
else
{
printf("ab都为零,c不为零,方程不成立\n");
}
}
else
{
printf("x=%lf\n",-c/b);
}
}
else if( d>=0 )
{
printf("x1=%lf\n",(-b+sqrt(d))/(2*a));
printf("x2=%lf\n",(-b-sqrt(d))/(2*a));
}
else
{
printf("x1=%lf+%lf\n",-b/(2*a),sqrt(-d)/(2*a));
printf("x2=%lf-%lf\n",-b/(2*a),sqrt(-d)/(2*a));
}
getch();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-04-02
展开全部
#include <stdio.h>
int main()
{
int a,b,m,c,d,n;
double x=0,y=0;
printf("Enter three integers(a,b,m):");
scanf("%d,%d,%d",&a,&b,&m);
printf("Enter three integers(c,d,n):");
scanf("%d,%d,%d",&c,&d,&n);
printf("%dx + %dy=%d\n",a,b,m);
printf("%dx + %dy=%d\n",c,d,n);
x=(m*d-b*n)/(a*d-b*c);
y=(m*c-a*n)/(b*c-a*d);
printf("The two lines intersect at point:(%.2lf,%.2lf)\n",x,y);
return 0;
}
请采纳
int main()
{
int a,b,m,c,d,n;
double x=0,y=0;
printf("Enter three integers(a,b,m):");
scanf("%d,%d,%d",&a,&b,&m);
printf("Enter three integers(c,d,n):");
scanf("%d,%d,%d",&c,&d,&n);
printf("%dx + %dy=%d\n",a,b,m);
printf("%dx + %dy=%d\n",c,d,n);
x=(m*d-b*n)/(a*d-b*c);
y=(m*c-a*n)/(b*c-a*d);
printf("The two lines intersect at point:(%.2lf,%.2lf)\n",x,y);
return 0;
}
请采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询