Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <iostream.h>
- #include <stdio.h>
- int main()
- {
- double A[101][101];
- double B[101][1];
- double X[101][1];
- double koeff, koeff2, temp1, temp2, temp3, temp4;
- int size, num=0;
- //-------------------------------------------------|
- cout<<"Vvedite razmer matricsi sistemi: ";
- cin>>size;
- cout<<"Vvedite element matricsi A: "<<endl;
- for ( int a1=0; a1<size; a1++)
- {
- for ( int a2=0; a2<size; a2++)
- {
- cin>>A[a1][a2];
- }
- }
- cout<<"Vvedennaya matricsa: "<<endl;
- for ( int a3=0; a3<size; a3++)
- {
- for ( int a4=0; a4<size; a4++)
- {
- cout<<A[a3][a4]<<" ";
- }
- cout<<endl;
- }
- //-------------------------------------------------|
- cout<<"Vvedite stolbecs svobodnich chlenov: ";
- for ( int b1=0; b1<size; b1++)
- {
- cin>>B[b1][0];
- }
- cout<<"Vvedennii stolbecs svobodnich chlenov: "<<endl;
- for ( int b2=0; b2<size; b2++)
- {
- cout<<B[b2][0]<<endl;
- }
- //-------------------------------------------------|
- double max=0;
- for ( int c1=0; c1<size; c1++)
- {
- if ( fabs(A[c1][0])>max)
- {
- max=A[c1][0];
- num=c1;
- }
- }
- cout<<max<<" "<<num+1<<endl;
- //-------------------------------------------------|
- for ( int d1=0; d1<size; d1++)
- {
- temp1=A[0][d1];
- A[0][d1]=A[num][d1];
- A[num][d1]=temp1;
- }
- temp2=B[0][0];
- B[0][0]=B[num][0];
- B[num][0]=temp2;
- cout<<"Vvedennaya matricsa: "<<endl;
- for ( int d2=0; d2<size; d2++)
- {
- for ( int d3=0; d3<size; d3++)
- {
- cout<<A[d2][d3]<<" ";
- }
- cout<<endl;
- }
- for ( int d4=0; d4<size; d4++)
- {
- cout<<B[d4][0]<<endl;
- }
- //-------------------------------------------------|
- for ( int e1=0; e1<size; e1++)
- {
- for ( int e2=e1; e2<size-1; e2++)
- {
- koeff=A[e2+1][e1]/A[e1][e1];
- B[e2+1][0]=B[e2+1][0]-B[e1][0]*koeff;
- for ( int e3=e1; e3<size; e3++)
- {
- A[e2+1][e3]=A[e2+1][e3]-A[e1][e3]*koeff;
- }
- }
- }
- cout<<"Vvedennaya matricsa: "<<endl;
- for ( int e4=0; e4<size; e4++)
- {
- for ( int e5=0; e5<size; e5++)
- {
- // cout<<A[e4][e5]<<" ";
- printf("%0.6lf \t" , A[e4][e5]);
- }
- // cout<<endl;
- printf("\n");
- }
- for ( int e6=0; e6<size; e6++)
- {
- // cout<<B[e6][0]<<endl;
- printf("%0.6lf \n", B[e6][0]);
- }
- //-------------------------------------------------|
- /*
- for ( int f1=size; f1>0; f1--)
- {
- for ( int f2=f1; f2>0+1; f2--)
- {
- koeff=A[f2-1][f1]/A[f1][f1];
- B[f2-1][0]=B[f2-1][0]-B[f1][0]*koeff;
- for ( int f3=f1; f3>0; f3--)
- {
- A[f2-1][f3]=A[f2-1][f3]-A[f1][f3]*koeff;
- }
- }
- }
- cout<<"Vvedennaya matricsa: "<<endl;
- for ( int f4=0; f4<size; f4++)
- {
- for ( int f5=0; f5<size; f5++)
- {
- cout<<A[f4][f5]<<" ";
- }
- cout<<endl;
- }
- for ( int f6=0; f6<size; f6++)
- {
- cout<<B[f6][0]<<endl;
- }
- */
- //-------------------------------------------------|
- for ( int f1=size; f1>0; f1--)
- {
- for ( int f2=f1; f2>1; f2--)
- {
- koeff2=A[f2-1][f1]/A[f1][f1];
- B[f2-1][0]=B[f2-1][0]-B[f1][0]*koeff2;
- for ( int f3=f1; f3>0; f3--)
- {
- A[f2-1][f3]=A[f2-1][f3]-A[f1][f3]*koeff;
- }
- }
- }
- cout<<"Vvedennaya matricsa: "<<endl;
- for ( int f4=0; f4<size; f4++)
- {
- for ( int f5=0; f5<size; f5++)
- {
- // cout<<A[f4][f5]<<" ";
- printf("%0.6lf \t" , A[f4][f5]);
- }
- // cout<<endl;
- printf("\n");
- }
- for ( int f6=0; f6<size; f6++)
- {
- // cout<<B[f6][0]<<endl;
- printf("%0.6lf \n", B[f6][0]);
- }
- //-------------------------------------------------|
- /*
- for(r=1;r<n;r++)
- {
- for(i=1;i<=r;i++)
- {
- t=mas[i-1][r]/mas[r][r];
- B[i-1]=B[i-1]-B[r]*t;
- for(j=r;j<n;j++)
- {
- mas[i-1][j]=mas[i-1][j]-mas[r][j]*t;
- }
- }
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement