By GokiSoft.com|
19:57 07/12/2021|
Lập Trình C
Bài tập - Giải hệ phương trình bậc nhất nhất 2 ẩn - Lập trình C
Giải hệ phương trình bậc nhất nhất 2 ẩn
a1x + b1y = c1
a2x + b2y = c2
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Nguyễn đình quân [T2008A]](https://www.gravatar.com/avatar/46aca6afcfe99fdb28357afb847d8a0c.jpg?s=80&d=mm&r=g)
Nguyễn đình quân
2020-09-11 10:22:10
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a1, b1, c1, a2, b2, c2;
float D,Dx,Dy , x ,y;
printf("a1*x+b1*y=c1\n");
printf("a2*x+b2*y=c2\n");
printf("\nNhap a1:");
scanf("%d",&a1);
printf("\nhap b1:");
scanf("%d",&b1);
printf("\nhap c1:");
scanf("%d",&c1);
printf("\nhap a2:");
scanf("%d", &a2);
printf("\nhap b2:");
scanf("%d", &b2);
printf("\nhap c2:");
scanf("%d", &c2);
D = a1 * b2 - a2 * b1;
Dx = c1 * b2 - c2 * b1;
Dy = a1 * c2 - a2 * c1;
if (D == 0) {
if (Dx + Dy == 0)
printf("He phuong trinh co vo so nghiem");
else
printf("He phuong trinh vo nghiem");
}
else {
x = Dx / D;
y = Dy / D;
printf("He phuong trinh co nghiem (x, y) = (%d, %d)", x, y);
}
return 0;
}
![hainguyen [community]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-11 10:09:37
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
float a1, b1, c1, a2, b2, c2, x, y, D, Dx, Dy;
printf("\nNHap a1 =");
scanf("%f", &a1);
printf("\nNhap b1 =");
scanf("%f", &b1);
printf("\nNhap c1 =");
scanf("%f", &c1);
printf("\nNhap a2 =");
scanf("%f", &a2);
printf("\nNhap b2 =");
scanf("%f", &b2);
printf("\nNhap c2 =");
scanf("%f", &c2);
D = a1*b2 - a2*b1;
Dx = c1*b2 - c2*b1;
Dy = a1*c2 - a2*c1;
if(D==0){
printf("\nPTVN");
}else{
x = Dx/D;
y = Dy/D;
printf("\nPTCN (x,y) = (%g,%g)", x, y);
}
return 0;
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2020-09-11 09:38:18
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a1, b1, c1, a2, b2, c2;
printf("nhap a1: "); scanf("%d",&a1);
printf("nhap b1: "); scanf("%d",&b1);
printf("nhap c1: "); scanf("%d",&c1);
printf("nhap a2: "); scanf("%d",&a2);
printf("nhap b2: "); scanf("%d",&b2);
printf("nhap c2: "); scanf("%d",&c2);
float d, d1, d2, x, y;
d=a1*b2-a2*b1;
d1=b1*c2-b2*c1;
d2=a1*c2-a2*c1;
if(d==0){
if(d1-d2==0)
printf("\nHe pt co vo so nghiem");
else
printf("\nHe pt vo nghiem"); }
else {
x=d1/d;
y=d2/d;
printf("\nHe pt co 1 nghiem la(x,y)=(%f,%f)",x, y);
}
return 0;
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-09-11 09:29:28
#include<stdio.h>
int main(){
float D, Dx, Dy, x, y,a1, b1, c1, a2, b2, c2;
printf("a1*x + b1*y = c1\n");
printf("a2*x + b2*y = c2\n");
printf("\nNhap a1: ");
scanf("%f", &a1);
printf("\nNhap b1: ");
scanf("%f", &b1);
printf("\nNhap c1: ");
scanf("%f", &c1);
printf("\nNhap a2: ");
scanf("%f", &a2);
printf("\nNhap b2: ");
scanf("%f", &b2);
printf("\nNhap c2: ");
scanf("%f", &c2);
D = a1 * b2 - a2 * b1;
Dx = c1 * b2 - c2 * b1;
Dy = a1 * c2 - a2 * c1;
if (D==0)
printf("He phuong trinh tren vo nghiem");
else{
x = Dx / D;
y = Dy / D;
printf("He phuong trinh co nghiem (x, y) = (%g, %g)", x, y);
}
}
![Đặng Trần Nhật Minh [T2008A]](https://www.gravatar.com/avatar/ee8dc5a777ad26f3a962e86c233437cf.jpg?s=80&d=mm&r=g)
Đặng Trần Nhật Minh
2020-09-11 09:09:13
#include "bits/stdc++.h"
int main() {
float a1, a2, b1, b2, c1, c2, x, y, D, Dx, Dy;
printf("Solving Equation System Type:\n| a1 * x + b1 * y = c1\n| a2 * x + b2 * y = c2\n============================\n");
printf("a1 = "); scanf("%f", &a1);
printf("b1 = "); scanf("%f", &b1);
printf("c1 = "); scanf("%f", &c1);
printf("a2 = "); scanf("%f", &a2);
printf("b2 = "); scanf("%f", &b2);
printf("c2 = "); scanf("%f", &c2);
D = a1 * b2 - a2 * b1;
Dx = c1 * b2 - c2 * b1;
Dy = a1 * c2 - a2 * c1;
if (D == 0)
if (Dx + Dy == 0) printf("INFINITE SOLUTIONS");
else printf("NO SOLUTION");
else {
x = Dx / D;
y = Dy / D;
if (x == (int)x && y == (int)y) printf("(x, y) = (%.0f, %.0f)", x, y);
else if (x == (int)x && y != (int)y) printf("(x, y) = (%.0f, %.2f)", x, y);
else if (x != (int)x && y == (int)y) printf("(x, y) = (%.2f, %.0f)", x, y);
else printf("(x, y) = (%.2f, %.2f)", x, y);
}
}