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
9e32c10d
authored
Oct 17, 2024
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
3fe12f06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
Tunnitöö 17.10.24/ReaVeeruElementideVahetus.c
Tunnitöö 17.10.24/ReaVeeruElementideVahetus.c
0 → 100644
View file @
9e32c10d
/* Teostada rea ja massiivi elementide vahetuse.
/* Teostada rea ja massiivi elementide vahetuse.
* Kahe alamfunktsioonina: väljatrükk massiivist
* ja vahetavatest vektoritest.*/
#include <stdio.h>
//Prototüübid
int
loe
(
char
[],
int
,
int
);
void
lugemineMaatr
(
char
[],
int
k
,
int
[
k
][
k
]);
void
vahetus
(
char
[],
int
n
,
int
,
int
,
int
[][
n
],
int
[],
int
[]);
void
trykkMaatriks
(
char
[],
int
k
,
int
[][
k
]);
void
trykkVektor
(
char
[],
int
,
int
[]);
int
main
(
void
)
{
int
n
,
r
,
v
;
int
min
=
0
,
max
=
10
;
n
=
loe
(
"maatriksi mõõde:"
,
min
,
max
);
int
M
[
n
][
n
],
R
[
n
],
V
[
n
];
lugemineMaatr
(
"algab maatriksi elementide sisestus"
,
n
,
M
);
r
=
loe
(
"Rea number"
,
n
,
min
);
v
=
loe
(
"Veeru number"
,
n
,
min
);
vahetus
(
"algab vahetus"
,
n
,
r
,
v
,
M
,
R
,
V
);
trykkMaatriks
(
"maatriksi ise"
,
n
,
M
);
trykkVektor
(
"Rea trükk"
,
n
,
R
);
//Saame mitu korda kasutada ühte funktsiooni
trykkVektor
(
"Veeru trükk"
,
n
,
V
);
return
0
;
}
int
loe
(
char
teade
[],
int
min
,
int
max
)
{
int
arv
;
printf
(
"%s
\n
"
,
teade
);
do
{
printf
(
"Sisesta arv vahemikus %d...%d
\n
"
,
min
,
max
);
scanf
(
"%d"
,
&
arv
);
}
while
(
arv
<
min
||
arv
>
max
);
return
arv
;
}
void
lugemineMaatr
(
char
teade
[],
int
k
,
int
maatriks
[][
k
])
{
int
i
,
j
;
printf
(
"
\n
%s
\n
"
,
teade
);
for
(
i
=
0
;
i
<
k
;
i
++
)
{
for
(
j
=
0
;
j
<
k
;
j
++
)
{
printf
(
"Element kohal %d, %d"
,
i
,
j
);
scanf
(
"%d"
,
&
maatriks
[
i
][
j
]);
}
}
}
void
vahetus
(
char
teade
[],
int
n
,
int
x
,
int
y
,
int
m
[][
n
],
int
X
[],
int
Y
[])
{
int
i
;
printf
(
"
\n
%s"
,
teade
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
X
[
i
]
=
m
[
i
][
x
];
Y
[
i
]
=
m
[
y
][
i
];
m
[
i
][
x
]
=
Y
[
i
];
m
[
y
][
i
]
=
X
[
i
];
}
}
void
trykkMaatriks
(
char
teade
[],
int
n
,
int
maatriks
[][
n
])
{
int
i
,
j
;
printf
(
"%s
\n
"
,
teade
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
0
;
j
<
n
;
j
++
)
{
printf
(
"%d"
,
maatriks
[
i
][
j
]);
}
}
}
void
trykkVektor
(
char
teade
[],
int
n
,
int
m
[])
{
int
i
;
printf
(
"%s
\n
"
,
teade
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%d"
,
m
[
i
]);
}
}
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