用C语言实现二元一次方程组的计算
时间: 2024-02-07 15:02:58 浏览: 151
求解二元一次方程组的C语言代码
#include <stdio.h>
int main() {
float a1, b1, c1, a2, b2, c2;
float x, y;
printf("请输入二元一次方程组的系数,格式为 a1x + b1y = c1 和 a2x + b2y = c2 \n");
printf("a1 = ");
scanf("%f", &a1);
printf("b1 = ");
scanf("%f", &b1);
printf("c1 = ");
scanf("%f", &c1);
printf("a2 = ");
scanf("%f", &a2);
printf("b2 = ");
scanf("%f", &b2);
printf("c2 = ");
scanf("%f", &c2);
float d = a1 * b2 - a2 * b1;
if (d == 0) {
printf("方程无解\n");
} else {
x = (c1 * b2 - c2 * b1) / d;
y = (a1 * c2 - a2 * c1) / d;
printf("x = %f, y = %f\n", x, y);
}
return 0;
}
阅读全文