#include
#include
using namespace std;
int main(){
int a1,a2,a3,b1,b2,b3,c1,c2,c3;
float x,y,n,m,p;
cout<<"a1="; cin>>a1;
cout<<"b1="; cin>>b1;
cout<<"c1="; cin>>c1;
cout< cout<<"a2="; cin>>a2;
cout<<"b2="; cin>>b2;
cout<<"c2="; cin>>c2;
cout< cout<<"a3="; cin>>a3;
cout<<"b3="; cin>>b3;
cout<<"c3="; cin>>c3;
n=a1/a2; m=b1/b2; p=c1/c2;
if(n=m && m!=0){
y=(c2*a1-a2*c1)*1.0/(b2*a1-a2*b1)*1.0;
x=(c1*b2*a1- a2*b1*c1-c2*a1*b1+a2*c1*b1)*1.0/(a1*a1*b2-a2*a1*b1)*1.0;
cout<cout<<"x="<}
else{
cout<<"tenglamalar sistemasi"<cout<<"yechimga ega emas"<}
return 0;
}
2.3 chiziqli tenglamalar sistemasini yechishda
Gauss Jordan,Kramer,matritsa usuli
Program to solve linear equations using Gaussian elimination in C++
#include
/* math.h header file is included for abs() function */
#include
using namespace std;
int main()
{
int i,j,k,n;
cout<<"\nEnter the no. of equations: ";
cin>>n;
/* if no of equations are n then size of augmented matrix will be n*n+1. So here we are declaring 2d array 'mat' of size n+n+1 */
float mat[n][n+1];
/* for n equations there will be n unknowns which will be stored in array 'res' */
float res[n];
cout<<"\nEnter the elements of the augmented matrix: ";
for(i=0;i{
for(j=0;j{
cin>>mat[i][j];
}
}
for(i=0;i{
for(j=i+1;j{
if(abs(mat[i][i]) < abs(mat[j][i]))
{
for(k=0;k{
/* swapping mat[i][k] and mat[j][k] */
mat[i][k]=mat[i][k]+mat[j][k];
mat[j][k]=mat[i][k]-mat[j][k];
mat[i][k]=mat[i][k]-mat[j][k];
}
}
}
}
/* performing Gaussian elimination */
Do'stlaringiz bilan baham: |