c++ giai he pt bac 1
#include <iostream>
#include <cmath>
using namespace std;
bool isSame(double x, double y){
return abs(x - y) < 1e-8;
}
int solve(double a1, double b1, double c1,
double a2, double b2, double c2, double& x, double& y){
double d = a1*b2 - a2*b1;
double dx = c1*b2 - c2*b1;
double dy = c1*a2 - c2*a1;
if (isSame(d, 0.0)){
if (isSame(dx, 0.0) && isSame(dy, 0.0)){
return 2;
} else
return 0;
} else{
x = dx / d;
y = -dy / d;
return 1;
}
}
int main(){
cout.precision(3);
cout.setf(ios::fixed);
int k, i;
double a1, b1, c1, a2, b2, c2, x, y;
cout<<"k = ";
cin>> k;
for (i=0; i<k; i++){
cin>> a1>> b1>> c1>> a2>> b2>> c2;
int result = solve(a1, b1, c1, a2, b2, c2, x, y);
switch(result){
case 0:
cout<<"Phuong trinh vo nghiem"<<endl;
break;
case 1:
cout<<"Phuong trinh co nghiem x = "<<x<<" va y = "<<y<<endl;
break;
case 2:
cout<<"Phuong trinh vo so nghiem"<<endl;
break;
}
}
system("pause");
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top