Вы находитесь на странице: 1из 33

6.

++
++ (), A,
4 5 ..

6 9 7 13
5
8
3
8
A=
3
7 88 33
55 77 88 37

19
22
71
61

() :
_ [n][m];
n ( 0 n-1),
m ( 0 m-1).
,
int x[10][15];
x, 10 15 (
0 9, 0 14).
,
, .
, x[2][4] x,
.
++ ,
:
_ [n1][n2][nk];

6.1. -
- . 6.1

i=0,N-1
j=0,M-1
ij
6.1.
C printf scanf
.
printf("N="); scanf("%d",&N);
printf("M="); scanf("%d",&M);
printf("\n Vvedite A \n");
for(i=0;i<N;i++)
1

for(j=0;j<M;j++)
{
scanf("%f",&b);
a[i][j]=b;
}
C cin cout
.
cout<<"N="; cin>>N;
cout<<"M="; cin>>M;
cout<<"\n Vvedite A \n";
for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>a[i][j];
- . 6.2

i=0,N-1
j=0,M-1

ij

(\n)
6.2.
C printf scanf
.
printf("\n Matrica A\n");
for(i=0;i<N;i++)
{for(j=0;j<M;j++)
printf("%f\t",a[i][j]);
printf("\n");}
C cin cout
.
cout<<"\n Matrica A\n";
for(i=0;i<N;cout<<endl,i++)
for(j=0;j<M;j++)
cout<<"\t"<<a[i][j]);
2

. 6.3 -
.

6.3.

A[0][0], ima=0, jmax=0.
, max,

, max,
. - . 6.4.
max=A[0][0]
imax=0
jmax=0
i=0;i<n;i++

j=0;j<m;j++
max, imax,
jmax
-

A[i][j]>max
+

max=A[i][j]
imax=i
jmax=j

6.4.


.
float a[20][20];
int i,j,n,m, imax, jmax;
float max;
//
...
max=a[0][0];
imax=0; jmax=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if (a[i][j]<max)
{
max=a[i][j];
imax=i;
jmax=j;
}
printf("\nmax=%f\n",max);
printf("\nimax=%d\n",imax);
printf("\njmax=%d\n",jmax);

,
(. . 6.5):
(i = j),
;
(i > j),
;
(i < j),
.
,
i + j +1 = n;
i + j + 1 < n
;
, ,
i + j + 1 > n.

i<j
i=j
i>j

i+j+1<N
i+j+1=N
i+j+1>N

6.5.
:
, ,
;
, ,
;
, ;
,
;
,
;
,
A= AT .
, ,
= ( ).

.
6.1. ,
.
5

- . 6.6.
S=0, i=0;i<N;i++

j=0;i<M;j++

S
i <j

+
S += A[i][j]

.6.6. - 6.1.
int main()
{int S,i,j,N,M,a[20][20];
cout<<"N=";cin>>N;
cout<<"M=";cin>>M;
cout<<"Input Matrix A"<<endl;
6

for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>a[i][j];
for(S=i=0;i<N;i++)
for(j=0;j<M;j++)
if (j>i) S+=a[i][j];
cout<<"S="<<S<<endl;}

.6.7 .

S=0, i=0;i<N;i++

j=i+1;j<M;j++
S

S += A[i][j]

6.7. 7.1
6.2.
, . -
.6.7.
N N

N-

N -

i + j+ 1= n j = n- i-1
7

6.7. - 6.2
8

#include <iostream>
using namespace std;
int main()
{int k,i,j,N,a[20][20];
cout<<"N=";cin>>N;
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
//
for(i=k=0;i<N;i++)
{ if(a[i][i]>0)k++;
if(a[i][N-i-1]>0)k++;}
// ,
// ,
//
for(i=1;i<N-1;i++)
{ if(a[0][i]>0)k++;
if(a[N-1][i]>0)k++;
if(a[i][0]>0)k++;
if(a[i][N-1]>0)k++;}
//, ,
//
if ((N%2!=0)&&(a[N/2][N/2]>0))k--;
cout<<"k="<<k<<endl;}
6.3. , .
,
, .
#include <iostream>
using namespace std;
int main()
{int pr,i,j,N,a[20][20];
cout<<"N=";cin>>N;cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
//, , pr=1.
for(pr=1,i=0;i<N;i++)
for(j=0;j<N;j++)
// 1,
// 0,
// , pr=0.
if (((i==j) && (a[i][j]!=1)) || ((i!=j) && (a[i][j]!=0)))
{
pr=0; break;
}
if (pr) cout<<" \n";
else cout<<" \n";}

6.4.
A(k,k).
, - .6.8.
#include <iostream>
using namespace std;
int main()
{
int i,j,k;
double b,a[20][20];
cout<<"k=";
cin>>k;
cout<<"Input Matrix A"<<endl;
for(i=0;i<k;i++)
for(j=0;j<k;j++)
cin>>a[i][j];
for(i=0;i<k;i++)
{
b=a[i][i];
a[i][i]=a[i][k-1-i];
a[i][k-1-i]=b;}
cout<<"Output Matrix A"<<endl;
for(i=0;i<k;cout<<endl,i++)
for(j=0;j<k;j++)
cout<<a[i][j]<<"\t";

i = 0; i<k; i++

b = a[i][i]
a[i][i]=a[i][k-i-1]
a[i][k-i-1]=b

6.8. - 6.4

6.5. A(N,M) ,

10

. ,

. - .6.9.

i = 0; i<N; i++

S =0

j =0; j<M;j++

S = S + A[i][j]

A[i][0] = S/M

6.9. - 6.5
#include <iostream>
using namespace std;
int main()
{int i,j,N,M;
double S,a[20][20];
cout<<"N=";
cin>>N;
cout<<"M=";
cin>>M;
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>a[i][j];
for(i=0;i<N;a[i][0]=S/M,i++)
for(S=j=0;j<M;j++)
S+=a[i][j];
cout<<"Output Matrix A"<<endl;
for(i=0;i<N;cout<<endl,i++)
for(j=0;j<M;j++)
cout<<a[i][j]<<"\t";}
6.6. A(m,n) ,
, c .
, ,

11

, -
. - .6.10.

i =0; i<M; i++

i%2 = 0

k=1; k<N; k++

k = 1; k< N ;k++

j =0; j<Nk; j++

j =0; j<Nk; j++

A[i][j]>A[i][j+1]

A[i][j]<A[i][j+1]

B = A[i][j]

B = A[i][j]

A[i][j] = A[i][j+1]
A[i][j+1] = B

A[i][j] = A[i][j+1]

A[i][j+1] = B

6.10. - 6.6
#include <iostream>
using namespace std;
int main()
{int i,j,k,N,M;
double b,a[20][20];
cout<<"M=";cin>>M;
cout<<"N=";cin>>N;
12

cout<<"Input Matrix A"<<endl;


for(i=0;i<M;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
for(i=0;i<M;i++)
//
if(i%2==0)
{//
for(k=1;k<N;k++)
for(j=0;j<N-k;j++)
if(a[i][j]>a[i][j+1])
{
b=a[i][j];
a[i][j]=a[i][j+1];
a[i][j+1]=b;
}
}
else//
for(k=1;k<N;k++)
for(j=0;j<N-k;j++)
if(a[i][j]<a[i][j+1])
{
b=a[i][j];
a[i][j]=a[i][j+1];
a[i][j+1]=b;
}
cout<<"Output Matrix A"<<endl;
for(i=0;i<M;cout<<endl,i++)
for(j=0;j<N;j++)
cout<<a[i][j]<<"\t";

6.2.
1-
.
, A(N,M)
NxM .
:
A=( *) calloc(n*m, sizeof())

A=( *) malloc(n*m*sizeof())

13

Ai,j , i
j k
. , k=i.M+j.
a[i][j] *(a+i*m+j)
2-
.
float **a;
float *, .

:
void main()
{
int n,m;
float **a;
// n float,
// // , ,
// float.
a=new float *[n];
// .
// 0 n-1,
// , m
// .
for(i=0;i<n;i++)
a[i]=new float(m);
//
// a[i]][j]
//
for(i=0;i<n;i++)
delete a[i];
delete [];
}
6.7. A(N,M).
. -
.6.11.
#include <iostream>
using namespace std;
//
//
int main()
{int i,j,imax,jmax,imin,jmin,N,M;
double min,max,b,*a;
cout<<"N=";cin>>N;
cout<<"M=";cin>>M;
14

max=min=a[0][0]
imax=jmax=imin=jmin=0

i=0;i<N;i++

j=0;j<N;j++

b=a[imax][jmax]
a[imax][jmax]=a[imin][jmin]
a[imin][jmin]=b
a[i][j]>max

+
max=a[i][j]
imax=i
jmax=j

a[i][j]<min

+
min=a[i][j]
imin=i
jmin=j

6.11. - 6.7
A=(double *) calloc(n*m, sizeof(double));
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
15

for(j=0;j<M;j++)
cin>>*(a+i*M+j);
for(max=min=*a,imax=jmax=imin=jmin=i=0;i<N;i++)
for(j=0;j<M;j++)
{ if ((*(a+i*M+j))>max)
{max=*(a+i*M+j); imax=i;jmax=j;}
if ((*(a+i*M+j))<min)
{min=*(a+i*M+j); imin=i;jmin=j;}}
b=*(a+imax*M+jmax);*(a+imax*M+jmax)=*(a+imin*M+jmin);
*(a+imin*M+jmin)=b;
cout<<"Output Matrix A"<<endl;
for(i=0;i<N;cout<<endl,i++)
for(j=0;j<M;j++)
cout<<*(a+i*M+j)<<"\t";}

6.8. A(n,m). P(m),



.

(. 6.12):
,
j- j- P.
#include <iostream>
using namespace std;
// .
int main()
{float max;float **a;int *p;int i,j,n,m,nmax;
cout<<"n=";
cin>>n;
cout<<"m=";
cin>>m;
a=new float *[n];
for(i=0;i<n;i++)
a[i]=new float(m);
p=new int[m];
cout<<"Vvod matrici"<<endl;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>a[i][j];
cout<<"Matrica"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<a[i][j]<<"\t";
cout<<endl;}
cout<<"Massiv P"<<endl;
for(j=0;j<m;j++)
{// j-
// i
max=a[0][j];
16

nmax=0;
for(i=1;i<n;i++)
if (a[i][j]>max)
{
max=a[i][j];
nmax=i;
}
// nmax i- p
p[j]=nmax;
cout<<p[j]<<"\t";
}
cout<<endl;
delete [] a;
return 0;
}

j=0, M-1

Max = A 0,j
Nmax = 0

i = 1, N-1

A i,j > Max

Pj = Nmax

Max = Ai,j
Nmax = i

6.12. - 6.8
17

6.9.
A(N,M) B(M,L).
a 00 a 01 a 02
b 00 b 01
a 10 a 11 a 12 b 10 b 10
a 20 a 21 a 22
b 20 b 21

a 00 b 00 a 01 b 10 a 02 b 20 a 00 b 01 a 01 b 11a 02 b 21
c 00 c 01
a 10 b 00 a 11 b 10 a 12 b 20 a 10 b 01 a 11 b 11a 12 b 21 = c 10 c 10
a 20 b 00 a 21 b 10 a 22 b 20 a 20 b 01a 21 b 11a 22 b 21
c 20 c 21
Cij :
M 1

C i , j = Aik Bkj , i = 0,N-1 j = 0,L-1.


k=0

,
,
. A B B A . -
. 6.13

i=0; i<N; i++

j=0; j<L; j++


S= 0
k=0; k<M; k++

S = S + A[i,k] B[k,j]

C[i,j] = S

6.13. -
int main()
{int i,j,k,N,L,M;
double **a, **b, **c;
18

cout<<"N=";
cin>>N;
cout<<"M=";
cin>>M;
cout<<"L=";
cin>>L;
a=new double *[N];
for(i=0;i<N;i++)
a[i]=new double[M];
b=new double *[M];
for(i=0;i<M;i++)
b[i]=new double[L];
c=new double *[N];
for(i=0;i<N;i++)
c[i]=new double[L];
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
cin>>a[i][j];
cout<<"Input Matrix B"<<endl;
for(i=0;i<M;i++)
for(j=0;j<L;j++)
cin>>b[i][j];
for(i=0;i<N;i++)
for(j=0;j<L;j++)
for(c[i][j]=0,k=0;k<M;k++)
c[i][j]+=a[i][k]*b[k][j];
cout<<"Matrix C"<<endl;
for(i=0;i<N;cout<<endl,i++)
for(j=0;j<L;j++)
cout<<c[i][j]<<"\t";
for(i=0;i<N;i++)
delete [] a[i];
delete [] a;
for(i=0;i<M;i++)
delete [] b[i];
delete [] b;
for(i=0;i<N;i++)
delete [] c[i];
delete [] c;}

19

7.

:
;
;
.
7.1.

7.1. (7.1).
a 00 x 0a 01 x 1...a 0n1 x n1=b 0
a 10 x 0 a 11 x 1...a 1n1 x n1=b1
...
a n10 x 0a n11 x 1...a n1n1 x n1=b n1

(7.1)

,
, :

A=

a 00
a 10
a n10

a 01 ... a 0n1
a 11 ... a 1n1
...
a n11 ... a n1n1


b0
b
b= 1
...
b n1

x0
x
x= 1
...
x n1

Ax = b.
- ,
(7.2) (7.3). ,
(7.2) .

A' =

a 00
a 10
a n10

a 01 ... a 0n1
b0
a 11 ... a 1n1
b1
...
a n11 ... a n1n1 b n1

a 00 a 01 ... a 0n1
b0
0 a 11 ... a 1n1
b1
A' =
...
0
0 ... an1n1 b n1

(7.2)

(7.3)

(7.3)
( ) , .
20

:
1- = 1- 0-
2- = 2- 0-

i- = i- 0-

n-1- = n-1- 0-
:

a 10=a 10Ma00

a 11=a 11Ma01

a 1i =a1i Ma0i

a 1n1 =a 1n1Ma0n1

b1 =b1 Mb0
a 10 Ma00 =0

M=

a 10
a 00

a 20 =a 20Ma 00

a 21 =a 21Ma 01

a 2i =a 2i Ma 0i

a 2n1 =a 2n 1 Ma 0n1

b 2=b 2Mb 0
a 20 Ma 00=0

M=

a 20
a 00

, i
:

a i0 =a i0 Ma 00

a i1=a i1Ma 01

a i n1 =ai n1Ma 0 n1

bi =b iMb0

a i0 Ma i0 =0
i :
M=

aik

a kk

(7.2),
21

, ..
(7.4). . 7.1.

1
k=0; k<n; k++

2
i=k+1; i<n; i++

3
M=a[i][k]/a[k][k], j=k; j<n;j++

4
a[i][j]-=M a[k][j]

5
b[i]-=M b[k]

7.1. -

a 00 x 0a 01 x 1a 02 x 2 ...a 0n1 x n1=b0
a 11 x 1a 02 x 2...a1n1 x n1=b 1
(7.4)
a 22 x 2...a 1n1 x n1=b1
...
a n1n1 x n1=b n1

22

(7.2) akk,
, - .
,
. k
( akk),
, , k-
. , , . 7.2.

7.2. -
(7.4) .
(n-1)- (7.4) :
a n1n1 x n1=b n1 .
a n1n10 , xn1 =

bn1

a n1n1
a n1n1=0 b n1=0 ,

,
.
a n1n1=0 b n1 0 .
(n2)- (7.4)
a n2n2 x n2a n2n1 x n1=b n2 .

23

xn2=

bn2a n2n1 x n1
.
a n2n2

(n3) - (7.4) :
a n3n3 x n3a n3n2 x n2 a n3n1 x n1 =bn3 ,
:

xn3 =

b n3a n3n2 x n2a n3n1 x n1


a n3n3

:
n1

a
x a
x
xn3 =b n3 n3n2 n2 n2n1 n1 =
a n3n3

bn3

j =n2

a n3 j x j

a n3n3

, i- x :
n1

b i
xi =

j =i1

a ij x j

i=n-1,...,0

aii

, ,
- . 7.3.

1
i=n-1; i>=0; i-2
s=0, j=i+1; i<n; i++
3

s+=a[i][j]x[j]

x i=(bi -s)/aii

7.3. -
.7.4 - .

24

k=0; k<n; k++

i=0; i<n; i++

max=|a[k][k]|
r=k

j=0; j<n; j++

i=k+1; i<n; i++


5

a[i][j]

10

11

b[i]

max=|a[i][k]|
r=i

19

+
20

a[n-1][n-1]=0

b[n]=0

23

i=n-1;i>=0;i--

21

|a[i][k]|>max

24

12

j=0; j<n; j++


13

c=a[k][j]
a[k][j]=a[r][j]
a[r][j]=c

s=0, j=i+1; j<n;j++


14

25

s+=a[i][j] x[j]
22

c=b[k]
b[k]=b[r]
b[r]=c

15

i=k+1; i<n; i++

26

x[i]=(b[i]-s)/a[i][i]

16

M=a[i][k]/a[k][k],j=k,j<n; j++
27

x[i]
28

17

a[i][j]-=M a[k][j]

18

b[i]-=M b[k]

7.4. -
, . 7.4
main() .
main() , SLAU
.
SLAU
.
25

:
. ,
, SLAU
() ,
-.
SLAU 0, , 1
, 2
.
int SLAU(double **matrica_a,int n,double *massiv_b,
double *x)
{
int i,j,k,r;
double c,M,max,s, **a, *b;
a=new double *[n];
for(i=0;i<n;i++)
a[i]=new double[n];
b=new double [n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=matrica_a[i][j];
for(i=0;i<n;i++)
b[i]=massiv_b[i];
for(k=0;k<n;k++)
{
max=fabs(a[k][k]);
r=k;
for(i=k+1;i<n;i++)
if (fabs(a[i][k])>max)
{
max=fabs(a[i][k]);
r=i;
}
for(j=0;j<n;j++)
{
c=a[k][j];
a[k][j]=a[r][j];
a[r][j]=c;
}
c=b[k];b[k]=b[r];b[r]=c;
for(i=k+1;i<n;i++)
{
for(M=a[i][k]/a[k][k],j=k;j<n;j++)
a[i][j]-=M*a[k][j];
b[i]-=M*b[k];
}
}
if (a[n-1][n-1]==0)
26

else
{

if(b[n-1]==0)
return -1;
else return -2;

for(i=n-1;i>=0;i--)
{
for(s=0,j=i+1;j<n;j++)
s+=a[i][j]*x[j];
x[i]=(b[i]-s)/a[i][i];
}
return 0;}
for(i=0;i<n;i++)
delete [] a[i];
delete [] a;
delete [] b;
}
int main()
{int result,i,j,N;
double **a, *b, *x;
cout<<"N=";
cin>>N;
a=new double *[N];
for(i=0;i<N;i++)
a[i]=new double[N];
b=new double [N];
x=new double [N];
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
cout<<"Input massiv B"<<endl;
for(i=0;i<N;i++)
cin>>b[i];
result=SLAU(a,N,b,x);
if (result==0)
{ cout<<"Massiv X"<<endl;
for(i=0;i<N;i++)
cout<<x[i]<<"\t";
cout<<endl;
}
else if (result==-1)
cout<<"Great number of Solution";
else if (result==-2)
cout<<"No solution";
for(i=0;i<N;i++)
27

delete [] a[i];
delete [] a; delete [] b; delete [] x; }

7.2.
7.2. A(N,N).

A=

a 00
a 10
a 20

a 01
a 11
a 21
...
an11

a n10

...
...
...

a 0n1
a 1n1
a 2n 1

(7.5)

... a n1n1

A1:

A-1=

y 00
y 10

y 01 ...
y 11 ...
...
y n11 ...

y n10

y 0n1
y 1n1

(7.6)

y n1n1

(7.6) (7.5),

AA =E

, :

a 00
a 10
a 20

a n10

a 01
a 11
a 21
...
a n11

...
...
...

a 0n1
y 00
a 1n1
y 10
a 2n1 y 20

... a n1n1

y n10

y 01
y 11
y 21
...
y n11

...
...
...
...

y 0n1
1
y 1n1
0
y 2n1 = 0
y n1n1

0
1
0
...
0 0

... 0
... 0
... 1
... 1

(7.5) (7.6)
:
a 00 y 00 a 01 y 10 ...a 0n1 y n10 =1
a 10 y 00a 11 y 10 ...a 1n1 y n10 =0
...
a n10 y 00 a n11 y 10...a n1n1 y n10 =0
, (7.5) i-
(7.6), :
a 00 y 0ia 01 y 1i...a 0n1 y n1i =0
a 10 y 0ia 11 y 1i ...a 1n1 y n1i=0
...
a i0 y 0i a i1 y 1i...a 1 y n1i=1
...
a n10 y 0ia n11 y 1i ...a n1n1 y n1i=0
28

n- :
a 00 y 0n1a 01 y 1n1...a 0n1 y n1n1=0
a 10 y 0n1a 11 y 1n1...a 1n1 y n1n1=0
.
...
a n10 y 0n1a n11 y 1n1...a n1n1 y n1n1=1
-
. 7.5. 25 .
3 ,
, . 6
.
,
25 ,
n. X i- , , i Y.
1

i=0;1 i<n; i++


2

j=0; j<n; j++

j=i
+

Bj = 1

Bj = 0

GAUSS(A,n,B,X)
7

j=0; j<n; j++

Yji = Xj

7.5. -
int SLAU(double **matrica_a,
int n, double *massiv_b,
double *x)
{
int i,j,k,r;
double c,M,max,s, **a, *b;
a=new double *[n];
for(i=0;i<n;i++) a[i]=new double[n];
29

b=new double [n];


for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=matrica_a[i][j];
for(i=0;i<n;i++)
b[i]=massiv_b[i];
for(k=0;k<n;k++)
{
max=fabs(a[k][k]);
r=k;
for(i=k+1;i<n;i++)
if (fabs(a[i][k])>max)
{
max=fabs(a[i][k]);
r=i; }
for(j=0;j<n;j++)
{
c=a[k][j];
a[k][j]=a[r][j];
a[r][j]=c;
}
c=b[k];
b[k]=b[r];
b[r]=c;
for(i=k+1;i<n;i++)
{
for(M=a[i][k]/a[k][k],j=k;j<n;j++)
a[i][j]-=M*a[k][j];
b[i]-=M*b[k];
}

if (a[n-1][n-1]==0)
if(b[n-1]==0)
return -1;
else return -2;
else
{for(i=n-1;i>=0;i--)
{for(s=0,j=i+1;j<n;j++)
s+=a[i][j]*x[j];
x[i]=(b[i]-s)/a[i][i];
}return 0;
}
for(i=0;i<n;i++)
delete [] a[i];
delete [] a;
delete [] b;
}
int INVERSE(double **a, int n, double **y)
{ int i,j,res;
double *b, *x;
b=new double [n];
x=new double [n];
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
30

if (j==i)
b[j]=1; else
b[j]=0;
res=SLAU(a,n,b,x);
if (res!=0) break;
else for(j=0;j<n;j++)
y[j][i]=x[j];

}
delete [] x;
delete [] b;
if (res!=0)
return -1;
else
return 0;}
int main()
{ int result,i,j,N;
double **a, **b;
cout<<"N=";
cin>>N;
a=new double *[N];
for(i=0;i<N;i++)
a[i]=new double[N];
b=new double *[N];
for(i=0;i<N;i++)
b[i]=new double[N];
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
result=INVERSE(a,N,b);
if (result==0)
{ cout<<"Inverse matrix"<<endl;
for(i=0;i<N;cout<<endl,i++)
for(j=0;j<N;j++)
cout<<b[i][j]<<"\t";
}
else
cout<<"No Inverse matrix"<<endl;
for(i=0;i<N;i++)
delete [] a[i];
delete [] a;
for(i=0;i<N;i++)
delete [] b[i];
delete [] b;
}

7.3.
7.3. A(N,N).

n1

det A= aii .
i=0

31

,
.
(7.2) (7.3)
. ,
- . 7.6,
,
.
1

Determinant(a,n)
15
2

i=0; i<n; i++

det=1

16

17

det*=a[i][i]

k=0; k<n; k++


4
max=|a[k][k]|
r=k
5

i=k+1,n

12
8

i=k+1; i<n;i++

r!=k

13

|a[i][k]|>max

+
9

det=-det

M=a[i][k],j=k;j<n;j++

14

a[i][j]-=M a[k][j]

max:=|a[i][k]|
r:=i

10

j=0; j<n; j++

11

c=a[k][j]
a[k][j]=a[r][j]
a[r][j]=c

7.6. -
32

,
. -
89. 8 , ,
, 9 . 15
16

.
double determinant(double **matrica_a, int n)
{ int i,j,k,r; double c,M,max,s,det=1, **a;
a=new double *[n];
for(i=0;i<n;i++) a[i]=new double[n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=matrica_a[i][j];
for(k=0;k<n;k++)
{
max=fabs(a[k][k]);
r=k;
for(i=k+1;i<n;i++)
if (fabs(a[i][k])>max)
{
max=fabs(a[i][k]);
r=i;
}
if (r!=k) det=-det;
for(j=0;j<n;j++)
{c=a[k][j]; a[k][j]=a[r][j];
a[r][j]=c;
}
for(i=k+1;i<n;i++)
for(M=a[i][k]/a[k][k],j=k;j<n;j++)
a[i][j]-=M*a[k][j];
}
for(i=0;i<n;i++)
det*=a[i][i];
return det;
}
int main()
{
int result,i,j,N;
double **a, b;
cout<<"N=";
cin>>N;
a=new double *[N];
for(i=0;i<N;i++)
a[i]=new double[N];
cout<<"Input Matrix A"<<endl;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
cin>>a[i][j];
cout<<"determinant="<<determinant(a,N)<<endl;
for(i=0;i<N;i++)
delete [] a[i];
delete [] a;}
33