# c++ 程式哪裡出錯了?

if a1x+b1y=c1 and a2x+b2y=c2

#include <iostream>

#include <windows.h>

using namespace std;

int main(){

int Deter, DeterX, DeterY, A1, A2, B1, B2, C1, C2;

int B1Sign, B2Sign, DeterX_Dem, DeterY_Dem;

bool Det_Ind=false;

SetConsoleTitle("Cramer's Rule");

cout<<"Program Written By Shawncplus To Solve a Linear Equation with Cramer's Rule"<< endl;

cin>>A1;

cin>>B1;

cin>>C1;

cin>>A2;

cin>>B2;

cin>>C2;

cout<<"The Equation is {\n";

B1Sign=B1*(-1);

B2Sign=B2*(-1);

if (B1>0){

cout<<"\t "<< A1 <<"x+"<<B1<<"y = "<< C1<< endl;}

else if (B1<0){

cout<<"\t "<< A1 <<"x-"<<B1Sign<<"y = "<< C1<< endl;}

if (B2>0){

cout<<"\t "<< A2 <<"x+"<<B2<<"y = "<< C2<< "\n\t\t} " <<endl;}

else if (B2<0){

cout<<"\t "<< A2 <<"x-"<<B2Sign<<"y = "<< C2<< "\n\t\t} " << endl;}

Deter=(A1*B2)-(A2*B1);

DeterX=(C1*B2)-(C2*B1);

DeterY=(A1*C2)-(A2*C1);

if (Deter==0 && DeterX==0 && DeterY==0) {

cout<<"System is Dependant (Infinite Solutions)"<< endl;

Det_Ind = true;

}

else if (Deter==0 && (DeterX!=0 || DeterY!=0)){

cout<<"System is Inconsistent (System Set is \xE9 )"<< endl;

Det_Ind = true;

}

cout<<"D = "<< Deter << endl;

cout<<"D(x) = "<< DeterX << endl;

cout<<"D(y) = "<< DeterY << endl;

if (Det_Ind==true){

cout<<"Please press Enter to continue. . .";

cin.get();

cin.get();

return 0;

}

2 個已更新項目:

else if (Det_Ind==false){

DeterX_Dem=(DeterX/Deter);

DeterY_Dem=(DeterY/Deter);

cout<<"\nX = "<< DeterX<<"/"<< Deter <<" = "<< DeterX_Dem << endl;

3 個已更新項目:

cout<<"Y = "<< DeterY<<"/"<< Deter <<" = "<< DeterY_Dem << endl;

cout<<"Solution Set is {("<< DeterX_Dem <<","<< DeterY_Dem

4 個已更新項目:

<<")}"<< endl;

}

cout<<"\n\nPlease press Enter to continue. . .";

5 個已更新項目:

cin.get();

cin.get();

return 0;

}

6 個已更新項目:

a1x+b1y=c1

a2x+b2y=c2

### 2 個解答

• 1 0 年前
最佳解答

標題與內文不一樣@@!

#include <stdio.h>

int main(void)

{

int Deter, DeterX, DeterY, A1, A2, B1, B2, C1, C2;

int B1Sign, B2Sign, DeterX_Dem, DeterY_Dem;

bool Det_Ind=false;

printf("Program Written By Shawncplus To Solve a Linear Equation with Cramer's Rule\n");

scanf("%d", &A1);

scanf("%d", &B1);

scanf("%d", &C1);

scanf("%d", &A2);

scanf("%d", &B2);

scanf("%d", &C2);

printf("The Equation is {\n");

B1Sign = B1*(-1);

B2Sign = B2*(-1);

if (B1>0){

printf("\t %dx+%dy = %d\n", A1, B1, C1);

}

else if (B1 < 0){

printf("\t %dx-%dy = %d\n", A1, B1Sign, C1);

}

if (B2>0){

printf("\t %dx+%dy = %d\n\t\t} \n", A2, B2, C2);

}

else if (B2<0){

printf("\t %dx-%dy = %d\n\t\t} \n", A2, B2Sign, C2);

}

Deter=(A1*B2)-(A2*B1);

DeterX=(C1*B2)-(C2*B1);

DeterY=(A1*C2)-(A2*C1);

if (Deter==0 && DeterX==0 && DeterY==0) {

printf("System is Dependant (Infinite Solutions)\n");

Det_Ind = true;

}

else if (Deter==0 && (DeterX!=0 || DeterY!=0)){

printf("System is Inconsistent (System Set is \xE9 )\n");

Det_Ind = true;

}

printf("D = %d\n", Deter);

printf("D(x) = %d\n", DeterX);

printf("D(y) = %d\n", DeterY);

if (Det_Ind==true){

printf("Please press Enter to continue. . .");

getchar();

getchar();

return 0;

}

else if (Det_Ind==false){

DeterX_Dem=(DeterX/Deter);

DeterY_Dem=(DeterY/Deter);

printf("\nX = %d/%d = %d\n", DeterX, Deter, DeterX_Dem);

printf("\nY = %d/%d = %d\n", DeterY, Deter, DeterY_Dem);

printf("Solution Set is {(%d,%d)}\n", DeterX_Dem, DeterY_Dem);

}

printf("\n\nPlease press Enter to continue. . .");

getchar();

getchar();

return 0;

}

參考資料： 自己
• 匿名使用者
7 年前

如果你很確定自己很想結婚

婚友社的確是一個有效率的管道

年紀越大壓力越大

以前我去婚友社時

年輕的女生機會總是比較多

時間總是不站在女生這邊的

所以如果你想婚的念頭已經確定

就去找一家評價好一點的婚友社!

行動吧!

這是我之前參加的婚友社我覺得不錯

或搜尋"紅娘李姐"

不過還是建議你自己去諮詢過看是否適合你!