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
01f03554
authored
Oct 12, 2024
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update MassiivSortFunktsioonid.c
parent
977f527d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
62 deletions
Tunnitöö 10.10.24/MassiivSortFunktsioonid.c
Tunnitöö 10.10.24/MassiivSortFunktsioonid.c
View file @
01f03554
/*Kasutaja sisestab 2 massiivi klaviatuurilt K1[n1], K2[n2]
#include <stdio.h>
/*Kasutaja sisestab 2 massiivi klaviatuurilt K1[n1], K2[n2]
#include <stdio.h>
* Massiivide elemendid liidetakse, moodustatakse
* uus massiiv K[n].
* salvestatakse uuele id massiivile
* Väljastatakse minimaalsete elementide massiiv,
* minimaalselt 3 alamprogrammi. */
#include <stdio.h>
//
Prototüübid
//
Prototüübid
int
sisestusN1
();
int
sisestusN1
();
int
sisestusN2
();
int
sisestusN2
();
int
sisestusM
();
int
sisestusM
();
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
void
Sortimine
(
int
,
int
[]);
void
Sortimine
(
int
,
int
[]);
void
V
ä
ljastus
(
int
,
int
,
int
[]);
void
V
ä
ljastus
(
int
,
int
,
int
[]);
int
main
(
void
)
int
main
(
void
)
{
{
int
n1
=
sisestusN1
();
int
n1
=
sisestusN1
();
int
n2
=
sisestusN2
();
int
n2
=
sisestusN2
();
int
M
=
sisestusM
();
int
M
=
sisestusM
();
int
n
=
n1
+
n2
;
int
n
=
n1
+
n2
;
int
K1
[
n1
];
int
K1
[
n1
];
int
K2
[
n2
];
int
K2
[
n2
];
int
K
[
n
];
int
K
[
n
];
...
@@ -33,75 +27,77 @@ int main(void)
...
@@ -33,75 +27,77 @@ int main(void)
V
ä
ljastus
(
M
,
n
,
K
);
V
ä
ljastus
(
M
,
n
,
K
);
return
0
;
return
0
;
}
}
int
sisestusN1
()
int
sisestusN1
()
{
{
int
n1
;
int
n1
;
printf
(
"Sisesta 1. massiivi liikmete arv n1
"
);
printf
(
"Sisesta 1. massiivi liikmete arv n1:
"
);
scanf
(
"%d"
,
&
n1
);
scanf
(
"%d"
,
&
n1
);
return
n1
;
return
n1
;
}
}
int
sisestusN2
()
{
int
sisestusN2
()
{
int
n2
;
int
n2
;
printf
(
"Sisesta 2. massiivi liikmete arv n2
"
);
printf
(
"Sisesta 2. massiivi liikmete arv n2:
"
);
scanf
(
"%d"
,
&
n2
);
scanf
(
"%d"
,
&
n2
);
return
n2
;
return
n2
;
}
}
int
sisestusM
()
{
int
sisestusM
()
{
int
M
;
int
M
;
printf
(
"Sisesta väljastatavate elementide arv M.
"
);
printf
(
"Sisesta väljastatavate elementide arv M:
"
);
scanf
(
"%d"
,
&
M
);
scanf
(
"%d"
,
&
M
);
return
M
;
return
M
;
}
}
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
//Massiivide sisselugemine
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
{
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K1
[
i
]);
scanf
(
"%d"
,
&
K1
[
i
]);
}
}
for
(
i
=
0
;
i
<
n2
;
i
++
)
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
{
printf
(
"Sisesta 2. massiivi element nr %d: "
,
i
);
printf
(
"Sisesta 2. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K2
[
i
]);
scanf
(
"%d"
,
&
K2
[
i
]);
}
}
}
}
void
V
ä
ljastusAlgne
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
void
V
ä
ljastusAlgne
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
{
{
int
i
;
int
i
;
printf
(
"
\n
Sisestatud massiiv nr 1. on: "
);
printf
(
"
\n
Sisestatud massiiv nr 1. on: "
);
for
(
i
=
0
;
i
<
n1
;
i
++
)
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
{
printf
(
"%d "
,
K1
[
i
]);
printf
(
"%d "
,
K1
[
i
]);
}
}
printf
(
"
\n
Sisestatud massiiv nr 2. on: "
);
printf
(
"
\n
Sisestatud massiiv nr 2. on: "
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
{
printf
(
"%d "
,
K2
[
i
]);
printf
(
"%d "
,
K2
[
i
]);
}
}
}
}
void
YhineMassiiv
(
int
n
,
int
n1
,
int
n2
,
int
K1
[],
int
K2
[],
int
K
[])
//K[n] moodustamine
void
YhineMassiiv
(
int
n
,
int
n1
,
int
n2
,
int
K
[],
int
K1
[],
int
K2
[])
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
{
K
[
i
]
=
K1
[
i
];
K
[
i
]
=
K1
[
i
];
}
}
for
(
i
=
n1
;
i
<
n
;
i
++
)
for
(
i
=
n1
;
i
<
n
;
i
++
)
{
{
K
[
i
]
=
K2
[
i
-
n1
];
K
[
i
]
=
K2
[
i
-
n1
];
}
}
}
}
void
Sortimine
(
int
n
,
int
K
[])
void
Sortimine
(
int
n
,
int
K
[])
{
{
int
Vahetus
;
int
Vahetus
;
int
i
;
int
i
;
int
sorditud
=
0
;
int
sorditud
=
0
;
...
@@ -109,22 +105,21 @@ void Sortimine(int n, int K[])
...
@@ -109,22 +105,21 @@ void Sortimine(int n, int K[])
while
(
sorditud
==
0
)
while
(
sorditud
==
0
)
{
{
sorditud
=
1
;
sorditud
=
1
;
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
{
{
if
(
K
[
i
]
>
K
[
i
+
1
])
if
(
K
[
i
]
>
K
[
i
+
1
])
{
{
Vahetus
=
K
[
i
];
Vahetus
=
K
[
i
];
K
[
i
]
=
K
[
i
+
1
];
K
[
i
]
=
K
[
i
+
1
];
K
[
i
+
1
]
=
Vahetus
;
K
[
i
+
1
]
=
Vahetus
;
sorditud
=
0
;
sorditud
=
0
;
}
}
}
}
}
}
}
}
void
V
ä
ljastus
(
int
M
,
int
n
,
int
K
[])
void
V
ä
ljastus
(
int
M
,
int
n
,
int
K
[])
{
{
int
i
;
int
i
;
printf
(
"
\n
%d elementi sorditud massiivist: "
,
M
);
printf
(
"
\n
%d elementi sorditud massiivist: "
,
M
);
for
(
i
=
0
;
i
<
M
&&
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
M
&&
i
<
n
;
i
++
)
...
@@ -132,5 +127,4 @@ void Väljastus(int M, int n, int K[])
...
@@ -132,5 +127,4 @@ void Väljastus(int M, int n, int K[])
printf
(
"%d "
,
K
[
i
]);
printf
(
"%d "
,
K
[
i
]);
}
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
\ No newline at end of file
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