-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmt4.cpp
112 lines (91 loc) · 1.3 KB
/
mt4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<iostream>
#include<math.h>
using namespace std;
int a1;
int b1;
int c1;
int a2;
int b2;
int c2;
float x;
float y;
int normal();
int b1eql0();
int b2eql0();
int check();
int main()
{
cout << "a1x+b1y=c1 \n";
cout << "a2x+b2y=c2 \n";
cout << "請輸入方程式1的x項值 \n";
cin >> a1;
cout << "請輸入方程式1的y項值 \n";
cin >> b1;
cout << "請輸入方程式1的c值 \n";
cin >> c1;
cout << "請輸入方程式2的x項值 \n";
cin >> a2;
cout << "請輸入方程式2的y項值 \n";
cin >> b2;
cout << "請輸入方程式2的c值 \n";
cin >> c2;
if (a2==0)
{
cout << "出現錯誤";
return 0;
}
if (b1==b2 && b2==0)
{
cout << "別玩我";
return 0;
}
if (a1/a2==b1/b2)
{
if (b1*c2 !=c1*b2)
{
normal();
}
else
{
cout << "無限多組解" ;
}
}
else
{
check();
}
return 0;
}
int normal()
{
cout << "有解\n";
x=(b2*c1-b1*c2)/(a1*b2-b1*a2);
y=(a2*c1-c2*a1)/(b1*a2-a1*b2);
cout << "x="<< x<<"\n";
cout << "y="<< y<<"\n";
}
int b1eql0()
{
x=a1/c1;
y=a2*x-c2;
cout << "x="<< x<<"\n";
cout << "y="<< y<<"\n";
}
int b2eql0()
{
x=a2/c2;
y=a1*x-c1;
cout << "x="<< x<<"\n";
cout << "y="<< y<<"\n";
}
int check()
{
if (b1==0)
{
b1eql0();
}
if (b2==0)
{
b2eql0();
}
}