English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

就是寫聯立解的方程式啊

我怎麼改 X一直等於1 Y一直等於0 要跑出無解時更怪..

請幫我看看哪裡有錯順便改正吧

謝謝

main()
{
float a, b, c, d, e, f, x, y;

printf("Input the coefficients of ax + by = c (a b c):");
scanf("%f %f %f",&a,&b,&c);

printf("Input the coefficients of dx + ey = f (d e f):");
scanf("%f %f %f",&d,&e,&f);

x = (c * e - b * f) / (a * e - b * d);

y = (a * f - c * d) / (a * e - b * d);

if (a * e - b * d == 0)
printf ("there is no solution or infinite solutions");
else if (a * e - b * d != 0)
printf ("The intersections are (%f, %f).\n", (c * e - b * f) / (a * e - b * d), (a * f - c * d) / (a * e - b * d) );
if (c * e - b * f == 0)
printf ("The intersections are (0.0, %f).\n", (c * e - b * f) / (a * e - b * d), (a * f - c * d) / (a * e - b * d) );
else if (c * e - b * f != 0)
printf ("The intersections are (%f, %f).\n", (c * e - b * f) / (a * e - b * d), (a * f - c * d) / (a * e - b * d) );
if (a * f - c * d == 0)
printf ("The intersections are (%f, 0.0).\n", (a * f - c * d) / (a * e - b * d), (c * e - b * f) / (a * e - b * d) );
else if (a * f - c * d != 0)
printf ("The intersections are (%f, %f).\n", (c * e - b * f) / (a * e - b * d), (a * f - c * d) / (a * e - b * d) );

system("Pause");

}

2007-10-14 14:13:10 · 2 個解答 · 發問者 宣儒 3 in 電腦與網際網路 程式設計

2 個解答

大大,妳沒設if條件怎麼知道解是如何

那就好比兩條直線可能相交(有解),可能共線(無限多解),可能不相交(無解)

2007-10-14 15:42:42 · answer #1 · answered by 宣儒 3 · 0 0

#include
#include
int main(int argc, char* argv[]){
//=====START=====//
double a1[3]={0},a2[3]={0},x,y;
printf("aX+bY=C\n");
printf("Input a1, b1, c1: "),scanf("%lf %lf %lf",(a1+0),(a1+1),(a1+2));
printf("Input a2, b2, c2: "),scanf("%lf %lf %lf",(a2+0),(a2+1),(a2+2));
x=(a1[2]*a2[1]-a2[2]*a1[1])/(a1[0]*a2[1]-a2[0]*a1[1]);
y=(a1[2]-a1[0]*x)/a1[1];
printf("X= %lf, Y= %lf\n",x,y);
//=====END=====//
system("PAUSE");
return 0;
}

2007-10-14 14:55:20 · answer #2 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers