sumber gambar : sdtimes.com
#include<iostream> #include<conio.h> using namespace std; int main(){ int a[3],b[3],c[3]; float hc,hb,ha,hsla,hslb; cout<<"Mencari Nilai X dan Y pada\nPersamaan Linier Dua Variabel\ndengan bentuk :\n"; cout<<"a1 + b1 = c1\n"; cout<<"a2 + b2 = c2\n"; cout<<"========================\n"; for(int i=1;i<3;i++){ cout<<"Masukkan Nilai a"<<i<<" : ";cin>>a[i]; cout<<"Masukkan Nilai b"<<i<<" : ";cin>>b[i]; cout<<"Masukkan Nilai c"<<i<<" : ";cin>>c[i]; } cout<<"\nSehingga menjadi :\n"; cout<<a[1]<<"x + "<<b[1]<<"y = "<<c[1]<<"\n"; cout<<a[2]<<"x + "<<b[2]<<"y = "<<c[2]<<"\n"; if(a[1] == a[2]) { int m; hb= b[1]-b[2]; hc= c[1]-c[2]; hslb= hc / hb; m= hslb * b[1]; ha= c[1]- m; hsla= ha / a[1]; } else { int m,ma,mb; float n,a1,b1,c1,a2,b2,c2; m= a[2] * a[1]; ma= m / a[1]; mb= m / a[2]; b1= b[1] * ma; c1= c[1] * ma; b2= b[2] * mb; c2= c[2] * mb; hb= b1-b2; hc= c1-c2; hslb= hc / hb; n= hslb * b[1]; ha = c[1] - n; hsla= ha / a[1]; } cout<<"\nJawabannya adalah :\n"; cout<<"Nilai x = "<<hsla<<"\n"; cout<<"Nilai y = "<<hslb<<"\n"; }
Dan hasilnya akan seperti ini:
Daftar Pustaka : tonie-di.blogspot.com
0 komentar: