Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jürgen Hein
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b289039c
authored
Oct 24, 2024
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a5a21f16
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
Tunnitöö 24.10.24/MaatriksLiitmine.c
Tunnitöö 24.10.24/MaatriksLiitmine.c
0 → 100644
View file @
b289039c
//liida kaks maatriksit;
//liida kaks maatriksit;
//maatriksid peavad olema
//ühesuurused;
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAX 15
//int sisestaInt(char[], int);
void
sisestaM_N
(
int
*
,
int
*
);
void
genereeriMaatriks
(
int
,
int
n
,
int
[][
n
]);
void
liidaMaatriks
(
int
,
int
n
,
int
[][
n
],
int
[][
n
],
int
[][
n
]);
void
valjastaMaatriks
(
char
[],
int
,
int
n
,
int
[][
n
]);
int
main
(
void
){
srand
(
time
(
NULL
));
//int m = sisestaInt("m");
//int n = sisestaInt("n");
int
m
,
n
;
sisestaM_N
(
&
m
,
&
n
);
int
M1
[
m
][
n
],
M2
[
m
][
n
],
Sum
[
m
][
n
];
genereeriMaatriks
(
m
,
n
,
M1
);
genereeriMaatriks
(
m
,
n
,
M2
);
liidaMaatriks
(
m
,
n
,
M1
,
M2
,
Sum
);
valjastaMaatriks
(
"Esimene liidetav:
\n
"
,
m
,
n
,
M1
);
valjastaMaatriks
(
"Teine liidetav:
\n
"
,
m
,
n
,
M2
);
valjastaMaatriks
(
"Summa:
\n
"
,
m
,
n
,
Sum
);
return
0
;
}
void
sisestaM_N
(
int
*
x
,
int
*
y
){
printf
(
"Sisesta maatriksite mõõtmed. (2...15)
\n
"
);
do
{
printf
(
"Read:"
);
scanf
(
"%d"
,
x
);
printf
(
"Tulbad:"
);
scanf
(
"%d"
,
y
);
}
while
(
*
x
>
MAX
||*
x
<
2
||*
y
>
MAX
||*
y
<
2
);
}
void
genereeriMaatriks
(
int
x
,
int
y
,
int
M
[][
y
]){
int
i
,
j
;
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
y
;
j
++
)
{
M
[
i
][
j
]
=
rand
()
%
100
+
1
;
}
}
}
void
liidaMaatriks
(
int
x
,
int
y
,
int
M1
[][
y
],
int
M2
[][
y
],
int
S
[][
y
]){
int
i
,
j
;
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
y
;
j
++
)
{
S
[
i
][
j
]
=
M1
[
i
][
j
]
+
M2
[
i
][
j
];
}
}
}
void
valjastaMaatriks
(
char
teade
[],
int
x
,
int
y
,
int
M
[][
y
]){
int
i
,
j
;
printf
(
"
\n
%s"
,
teade
);
for
(
i
=
0
;
i
<
x
;
i
++
)
{
printf
(
"
\n
"
);
for
(
j
=
0
;
j
<
y
;
j
++
)
{
printf
(
"%3d "
,
M
[
i
][
j
]);
}
}
printf
(
"
\n
"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment