二元一次方程组(C语言)
学生:潘卓华 施添耀
#include <stdio.h>
#include <math.h>
int main() {
double a1,b1,c1,a2,b2,c2,d,e,f;
printf("a1 b1 c1 : ");
scanf("%lf %lf %lf",&a1,&b1,&c1);
printf("a2 b2 c2 : ");
scanf("%lf %lf %lf",&a2,&b2,&c2);
d = a1 * b2 - b1 * a2;
e = c1 * b2 - b1 * c2;
f = a1 * c2 - c1 * a2;
if(fabs(d) <= 1.0E-6) printf("No answer。\n");
else if((fabs(a1/a2 - b1/b2) <= 1.0E-6) && (fabs(a1/a2 - c1/c2) <= 1.0E-6))
printf("INF\n");
else printf("x = %.3lf, y = %.3lf\n",e/d,f/d);
return 0;
}
时间: 2024-10-19 21:10:40