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 BT1871

Giải hệ phương trình bậc nhất nhất 2 ẩn


a1x + b1y = c1
a2x + b2y = c2


Liên kết rút gọn:

https://gokisoft.com/1871

Bình luận

avatar
Âu Duy Quyền [c_online]
2022-10-02 03:04:58



#include <stdio.h>
#include <stdlib.h>

/* Giai he pt bac nhat 2 an: a1x + b1y = c1
					    a2x + b2y = c2 */

int main(int argc, char *argv[]) {	

int a1, b1, c1, a2, b2, c2, D, Dx, Dy, x, y;

printf("Giai he phuong trinh 2 an sau");
printf("\na1x + b1y = c1");
printf("\na2x + b2y = c2");

printf("\nNhap a1, b1, c1, a2, b2, c2 ");
scanf("%d%d%d%d%d%d", &a1, &b1, &c1, &a2, &b2, &c2);

D = a1*b2 - b1*a2;
Dx = b1*c2 - c1*b2;
Dy = a1*c2 - c1*a2;

if(D == 0) {
	if(Dx == 0 && Dy == 0) {
		printf("HPT co vo so nghiem");
	} else {
		printf("HPT vo nghiem");
	}
} else {
	x = Dx / D;
	y = Dy / D;
	printf("HPT co nghiem x = %d, y = %d", x, y);
}

	return 0;
}


avatar
An Văn Minh [T2008A]
2020-09-14 06:44:52



#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
 {
	float a1,a2,b1,b2,c1,c2,x,y,D,Dx,Dy;
	
	printf("Nhap he so a1=");
	scanf("%f", &a1);
	
	printf("Nhap he so b1=");
	scanf("%f", &b1);
	
	printf("Nhap he so c1=");
	scanf("%f", &c1);
	
	printf("Nhap he so a2=");
	scanf("%f", &a2);
	
	printf("Nhap he so b2=");
	scanf("%f", &b2);
	
	printf("Nhap he so 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){
			printf("phuong trinh vo so nghiem");
		}else{
			printf("phuong trinh vo nghiem");
		}
	}else{
		x = Dx/D;
		y = Dy/D;
		printf("phuong trinh co nghiem x,y = %f,%f", x,y);
	}
	return 0;
	
}


avatar
Nguyễn Hữu Hiếu [T2008A]
2020-09-14 05:11:59



#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,a2,b1,b2,c1,c2,d,dx,dy,x,y;
	
	printf("\na1 = "); scanf("%f", &a1);
	printf("\na2 = "); scanf("%f", &a2);
	printf("\nb1 = "); scanf("%f", &b1);
	printf("\nb2 = "); scanf("%f", &b2);
	printf("\nc1 = "); scanf("%f", &c1);
	printf("\nc2 = "); scanf("%f", &c2);
		
	d = a1*b2 - a2*b1; dx = c1*b2 - c2*b1; dy = a1*c2 - a2*c1;
	
	
 	if (d == dx && d == dy && dy == 0) { printf("\nPT VSN"); } 
 	
	if (d == 0) { printf("\nPT VN"); }
 		
	else { 
		x = dx/d; y = dy/d;printf("\nx = %f, \ny = %f", x, y); 
		}
		
	return 0;
}


avatar
Nguyễn Xuân Mai [T2008A]
2020-09-12 15:51:40



	float a1,a2,b1,b2,c1,c2,x,y,D,Dx,Dy;
	printf("\nNhap a1:");
	scanf("%f",&a1);
	printf("\nNhap a2:");
	scanf("%f",&a2);
	printf("\nNhap b1:");
	scanf("%f",&b1);
	printf("\nNhap b2:");
	scanf("%f",&b2);
	printf("\nNhap c1:");
	scanf("%f",&c1);
	printf("\nNhap 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){
			printf("\npt vo so nghiem");
		}else{
			printf("\npt vo nghiem");
		}
	}else{
		x = Dx/D;
		y = Dy/D;
		printf("\nNghiem x = %f, y = %f", x,y);
	}	
	


avatar
Do Trung Duc [T2008A]
2020-09-12 14:03:16



#include <stdio.h>
#include <stdlib.h>
#include <math.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,a2,b1,b2,c1,c2,x,y,D,Dx,Dy;
	
	printf("Nhap he so a1=");
	scanf("%f", &a1);
	
	printf("Nhap he so b1=");
	scanf("%f", &b1);
	
	printf("Nhap he so c1=");
	scanf("%f", &c1);
	
	printf("Nhap he so a2=");
	scanf("%f", &a2);
	
	printf("Nhap he so b2=");
	scanf("%f", &b2);
	
	printf("Nhap he so 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){
			printf("phuong trinh vo so nghiem");
		}else{
			printf("phuong trinh vo nghiem");
		}
	}else{
		x = Dx/D;
		y = Dy/D;
		printf("phuong trinh co nghiem x,y = %f,%f", x,y);
	}
	return 0;
	
}


avatar
Trần Thị Khánh Huyền [T2008A]
2020-09-12 13:31:11



#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;
	printf("Nhap gia tri a1 ="); scanf("%f", &a1);
	printf("Nhap gia tri a2 ="); scanf("%f", &a2);
	printf("Nhap gia tri b1 ="); scanf("%f", &b1);
	printf("Nhap gia tri b2 ="); scanf("%f", &b2);
	printf("Nhap gia tri c1 ="); scanf("%f", &c1);
	printf("Nhap gia tri c2 ="); scanf("%f", &c2);
	float D, Dx, Dy;
	D = a1*b2-b1*a2;
	Dx = c1*b2-b1*c2;
	Dy = a1*c2-c1*a2;
	if (D!=0){
		x=Dx/D;
		y=Dy/D;
		printf ("\nHe phuong trinh co nghiem x=%f",x);
		printf ("\nHe phuong trinh co nghiem y=%f",y);}
		else {if (Dx==0 &&Dy==0) {printf("PTVSN");}
		     else{printf("PTVN");
			 }}
		
	return 0;
}


avatar
Nguyễn Anh Vũ [T2008A]
2020-09-12 13:10:35



#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[]) {
	//bat dau code;
	int a1, a2, b1, b2, c1, c2;
	float d, dx, dy, x, y;
	printf("a1*x+b1*y=c1");
	printf("\nNhap gia tri cua a1 =");
	scanf("%d, &a1");
	printf("\nNhap gia tri cua b1 =");
	scanf("%d, &b1");
	printf("\nNhap gia tri cua c1 =");
	scanf("%d, &c1");
	
	printf("a2*x+b2*y=c2");
	printf("\nNhap gia tri cua a2 =");
	scanf("%d, &a2");
	printf("\nNhap gia tri cua b2 =");
	scanf("%d, &b2");
	printf("\nNhap gia tri cua c2 =");
	scanf("%d, &c2");
	
	d=a1*b2-a1*b1;
	dx=c1*b2-c2*b1;
	dy=a1*c2-a2*c1;
	
	     if(d==0){ 
	     if(dx+dy==0)
	printf("\nHe phuong trinh vo so nghiem");
}	
	printf("\nHe phuong trinh vo nghiem");
		 	
	      x = dx / d;
              y = dy / d;
	printf("\nPhuong trinh có 2 nghiem x,y = %d%d",x,y);	  	
		
	//ket thuc code;
	return 0;
}


avatar
Trần Văn Lâm [T2008A]
2020-09-12 06:48:30



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;
	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("\nnhap b1: ");
	scanf("%d", &b1);
	printf("\nnhap c1: ");
	scanf("%d", &c1);
    printf("\nnhap a2: ");
	scanf("%d", &a2);
	printf("\nnhap b2: ");
	scanf("%d", &b2);
    printf("\nnhap 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 ==s 0);
		printf("He phuong trinh co vo so nghiem");
		printf("He phuong trinh vo nghiem");
	}
	{
		x = Dx / D;
		y = Dy / D;
		printf("He phuong trinh co nghiem x,y");
		scanf("%d%d", &x, &y);
	}
	
	return 0;
}


avatar
nguyễn Sử [T2008A]
2020-09-11 13:23:13



#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(" giai he phuong trinh bac nhat 2 an /n ");
	
printf("\nGia tri a1 = ");
scanf("%d, &a1");

printf("\nGia tri b1 = ");
scanf("%d, &b1");

printf("\nGia tri c1 = ");
scanf("%d, &c1");

printf("\nGia tri a2 = ");
scanf("%d, &a2");

printf("\nGia tri b2 = ");
scanf("%d, &b2");

printf("\nGia tri c2 = ");
scanf("%d, &c2");

	D = a1*b2 - a2*b1;
    Dx = c1*b2 - c2*b1;
    Dy = a1*c2 - a2*1;
    
    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;
}


avatar
vuong huu phu [T2008A]
2020-09-11 13:06:26



#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,a2,b1,b2,c1,c2;
	float d,dx,dy,x,y;
	
	printf("\nNhap gia tri cua a1 = ");
	scanf("%d",&a1);
	
	printf("\nNhap gia tri cua a2 = ");
	scanf("%d",&a2);
	
	printf("\nNhap gia tri cua b1= ");
	scanf("%d",&b1);
	
	printf("\nNhap gia tri cua b2 = ");
	scanf("%d",&b2);
	
	printf("\nNhap gia tri cua c1 = ");
	scanf("%d",&c1);
	
    printf("\nNhap gia tri cua 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("\n pt co vo so nghiem");
	else
	printf("\n pt vo nghiem");
	}
		
	else{
	 x = dx / d;
         y = dy / d;
	printf("\n pt co nghiem (x,y) = (%d,%d)",x,y);
	}

	return 0;
}