SHOW:
|
|
- or go back to the newest paste.
1 | #include <math.h> | |
2 | #include <iostream.h> | |
3 | #include <stdio.h> | |
4 | ||
5 | int main() | |
6 | { | |
7 | ||
8 | double A[101][101]; | |
9 | double B[101][1]; | |
10 | double X[101][1]; | |
11 | double koeff, koeff2, temp1, temp2, temp3, temp4; | |
12 | int size, num=0; | |
13 | ||
14 | //-------------------------------------------------| | |
15 | ||
16 | cout<<"Vvedite razmer matricsi sistemi: "; | |
17 | cin>>size; | |
18 | ||
19 | cout<<"Vvedite element matricsi A: "<<endl; | |
20 | for ( int a1=0; a1<size; a1++) | |
21 | { | |
22 | for ( int a2=0; a2<size; a2++) | |
23 | { | |
24 | cin>>A[a1][a2]; | |
25 | } | |
26 | } | |
27 | ||
28 | cout<<"Vvedennaya matricsa: "<<endl; | |
29 | for ( int a3=0; a3<size; a3++) | |
30 | { | |
31 | for ( int a4=0; a4<size; a4++) | |
32 | { | |
33 | cout<<A[a3][a4]<<" "; | |
34 | } | |
35 | cout<<endl; | |
36 | } | |
37 | //-------------------------------------------------| | |
38 | ||
39 | cout<<"Vvedite stolbecs svobodnich chlenov: "; | |
40 | for ( int b1=0; b1<size; b1++) | |
41 | { | |
42 | cin>>B[b1][0]; | |
43 | } | |
44 | ||
45 | cout<<"Vvedennii stolbecs svobodnich chlenov: "<<endl; | |
46 | for ( int b2=0; b2<size; b2++) | |
47 | { | |
48 | cout<<B[b2][0]<<endl; | |
49 | } | |
50 | ||
51 | //-------------------------------------------------| | |
52 | ||
53 | double max=0; | |
54 | for ( int c1=0; c1<size; c1++) | |
55 | { | |
56 | if ( fabs(A[c1][0])>max) | |
57 | { | |
58 | max=A[c1][0]; | |
59 | num=c1; | |
60 | } | |
61 | } | |
62 | ||
63 | cout<<max<<" "<<num+1<<endl; | |
64 | ||
65 | //-------------------------------------------------| | |
66 | ||
67 | for ( int d1=0; d1<size; d1++) | |
68 | { | |
69 | temp1=A[0][d1]; | |
70 | A[0][d1]=A[num][d1]; | |
71 | A[num][d1]=temp1; | |
72 | } | |
73 | ||
74 | temp2=B[0][0]; | |
75 | B[0][0]=B[num][0]; | |
76 | B[num][0]=temp2; | |
77 | ||
78 | cout<<"Vvedennaya matricsa: "<<endl; | |
79 | for ( int d2=0; d2<size; d2++) | |
80 | { | |
81 | for ( int d3=0; d3<size; d3++) | |
82 | { | |
83 | cout<<A[d2][d3]<<" "; | |
84 | } | |
85 | cout<<endl; | |
86 | } | |
87 | ||
88 | for ( int d4=0; d4<size; d4++) | |
89 | { | |
90 | cout<<B[d4][0]<<endl; | |
91 | } | |
92 | ||
93 | //-------------------------------------------------| | |
94 | ||
95 | for ( int e1=0; e1<size; e1++) | |
96 | { | |
97 | for ( int e2=e1; e2<size-1; e2++) | |
98 | { | |
99 | koeff=A[e2+1][e1]/A[e1][e1]; | |
100 | B[e2+1][0]=B[e2+1][0]-B[e1][0]*koeff; | |
101 | for ( int e3=e1; e3<size; e3++) | |
102 | { | |
103 | A[e2+1][e3]=A[e2+1][e3]-A[e1][e3]*koeff; | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | cout<<"Vvedennaya matricsa: "<<endl; | |
109 | for ( int e4=0; e4<size; e4++) | |
110 | { | |
111 | for ( int e5=0; e5<size; e5++) | |
112 | { | |
113 | - | cout<<A[e4][e5]<<" "; |
113 | + | // cout<<A[e4][e5]<<" "; |
114 | printf("%0.6lf \t" , A[e4][e5]); | |
115 | } | |
116 | // cout<<endl; | |
117 | printf("\n"); | |
118 | } | |
119 | ||
120 | - | cout<<B[e6][0]<<endl; |
120 | + | |
121 | { | |
122 | // cout<<B[e6][0]<<endl; | |
123 | printf("%0.6lf \n", B[e6][0]); | |
124 | } | |
125 | ||
126 | //-------------------------------------------------| | |
127 | /* | |
128 | for ( int f1=size; f1>0; f1--) | |
129 | { | |
130 | for ( int f2=f1; f2>0+1; f2--) | |
131 | { | |
132 | koeff=A[f2-1][f1]/A[f1][f1]; | |
133 | B[f2-1][0]=B[f2-1][0]-B[f1][0]*koeff; | |
134 | for ( int f3=f1; f3>0; f3--) | |
135 | { | |
136 | A[f2-1][f3]=A[f2-1][f3]-A[f1][f3]*koeff; | |
137 | } | |
138 | } | |
139 | } | |
140 | ||
141 | cout<<"Vvedennaya matricsa: "<<endl; | |
142 | for ( int f4=0; f4<size; f4++) | |
143 | { | |
144 | for ( int f5=0; f5<size; f5++) | |
145 | { | |
146 | cout<<A[f4][f5]<<" "; | |
147 | } | |
148 | cout<<endl; | |
149 | } | |
150 | ||
151 | for ( int f6=0; f6<size; f6++) | |
152 | { | |
153 | cout<<B[f6][0]<<endl; | |
154 | } | |
155 | */ | |
156 | //-------------------------------------------------| | |
157 | - | for ( int f2=f1; f2>0; f2--) |
157 | + | |
158 | for ( int f1=size; f1>0; f1--) | |
159 | { | |
160 | for ( int f2=f1; f2>1; f2--) | |
161 | { | |
162 | koeff2=A[f2-1][f1]/A[f1][f1]; | |
163 | B[f2-1][0]=B[f2-1][0]-B[f1][0]*koeff2; | |
164 | for ( int f3=f1; f3>0; f3--) | |
165 | { | |
166 | A[f2-1][f3]=A[f2-1][f3]-A[f1][f3]*koeff; | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
171 | cout<<"Vvedennaya matricsa: "<<endl; | |
172 | for ( int f4=0; f4<size; f4++) | |
173 | { | |
174 | for ( int f5=0; f5<size; f5++) | |
175 | { | |
176 | // cout<<A[f4][f5]<<" "; | |
177 | printf("%0.6lf \t" , A[f4][f5]); | |
178 | } | |
179 | // cout<<endl; | |
180 | printf("\n"); | |
181 | } | |
182 | ||
183 | for ( int f6=0; f6<size; f6++) | |
184 | { | |
185 | // cout<<B[f6][0]<<endl; | |
186 | printf("%0.6lf \n", B[f6][0]); | |
187 | } | |
188 | ||
189 | //-------------------------------------------------| | |
190 | /* | |
191 | for(r=1;r<n;r++) | |
192 | { | |
193 | for(i=1;i<=r;i++) | |
194 | { | |
195 | t=mas[i-1][r]/mas[r][r]; | |
196 | B[i-1]=B[i-1]-B[r]*t; | |
197 | for(j=r;j<n;j++) | |
198 | { | |
199 | mas[i-1][j]=mas[i-1][j]-mas[r][j]*t; | |
200 | } | |
201 | } | |
202 | } | |
203 | */ | |
204 | ||
205 | return 0; | |
206 | } |