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
Nguyễn đình quân [T2008A]
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;
}
	


avatar
hainguyen [community]
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;
}
		
	
	
 	


avatar
Triệu Văn Lăng [T2008A]
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;
}


avatar
Nguyễn Tiến Đạt [T2008A]
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);
    }
}


avatar
Đặng Trần Nhật Minh [T2008A]
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);
        
    }
	
}