[ create a new paste ] login | about

Link: http://codepad.org/37Y3OFHq    [ raw code | output | fork | 1 comment ]

C, pasted on Sep 6:
#include<stdio.h>
#include<conio.h>

// Giải hệ
/*
ax + by = c
dx + ey = f
*/
const int VoNghiem = 0, KhongXacDinh = -1;
int GiaiHePhuongTrinh(int a, int b, int c, int d, int e, int f, int &x, int &y)
{
	int D = a * e - d * b;
	int Dx = c * e - f * b;
	int Dy = a * f - d * c;

	int SoNghiem;
	if(D != 0)
	{
		x = Dx / D;
		y = Dy / D;
		printf("\nHe phuong trinh co 1 nghiem duy nhat: %d va %d", x, y);
		SoNghiem = 1;
	}
	else
	{
		if(Dx != 0 || Dy != 0)
		{
			printf("\nHe phuong trinh vo nghiem");
			SoNghiem = 0;
		}
		else if(Dx == Dy == 0)
		{
			printf("\nHe phuong trinh co vo so nghiem");
			SoNghiem = -1;
		}
	}
	return SoNghiem;
}
int main()
{
	int a, b, c, d, e, f, x, y;
	
	printf("\nNhap a: ");
	scanf("%d", &a);
	printf("\nNhap b: ");
	scanf("%d", &b);
	printf("\nNhap c: ");
	scanf("%d", &c);
	printf("\nNhap d: ");
	scanf("%d", &d);
	printf("\nNhap e: ");
	scanf("%d", &e);
	printf("\nNhap f: ");
	scanf("%d", &f);

	int SoNghiem = GiaiHePhuongTrinh(a, b, c, d, e, f, x, y);
	

	getch();
	return 0;
}

/*

*/


Output:
1
2
Line 17: error: conio.h: No such file or directory
Line 10: error: expected ';', ',' or ')' before '&' token


Create a new paste based on this one


Comments:
posted by DaddyDeady on Feb 20
Cho những ai yêu thích giải chi tiết bài này với c++:
``` cpp
#include <iostream>

using namespace std;

int main() {
float a, b, c;
cout << "Nhap lan luot 3 he so cua phuong trinh (1) (ax + by = c): ";
cin >> a >> b >> c;
float d, e, f;
cout << "Nhap lan luot 3 he so cua phuong trinh (2) (dx + ey = f): ";
cin >> d >> e >> f;
cout << "................Thinking................" << endl;
float D = (a*e) - (d*b);
float Dx = (c*e) - (b*f);
float Dy = (a*f) - (d*c);
if(D == 0) {
if(Dx != 0 || Dy != 0) {
cout << "He phuong trinh vo nghiem";
}
else {
if(a == 0) {
if(b == 0) {
if(c == 0) {
cout << "He phuong trinh co vo so nghiem voi moi cap nghiem (x, y)";
}
else {
cout << "He phuong trinh vo nghiem";
}
}
else {
cout << "He phuong trinh co vo so nghiem thoa man:" << endl;
cout << "Voi moi x thuoc R thi: y = " << c/b;
}
}
else {
if(b == 0) {
cout << "He phuong trinh co vo so nghiem thoa man: " << endl;
cout << "Voi moi y thuoc R thi: x = " << c/a;
}
else {
cout << "He phuong trinh co vo so nghiem thoa man: " << endl;
cout << "Voi moi x thuoc R thi: y = ";
if((-a/b) == -1) {
cout << "-x";
if((-c/b) != 0) {
cout << " + " << -c/b;
}
}
else if((-a/b) == 1) {
cout << "x";
if((-c/b) != 0) {
cout << " + " << -c/b;
}
}
else {
cout << -a/b << "x";
if((-c/b) != 0) {
cout << " + " << c/b;
}
}
}
}
}
}
else {
float x = Dx / D;
float y = Dy / D;
cout << "He phuong trinh co mot nghiem duy nhat (x; y) = (" << x << "; " << y << ")";
}

return 0;
}
reply