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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
137 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]
* 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
int
sisestusN1
();
int
sisestusN2
();
int
sisestusM
();
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
void
Sortimine
(
int
,
int
[]);
void
V
ä
ljastus
(
int
,
int
,
int
[]);
int
main
(
void
)
{
int
n1
=
sisestusN1
();
int
n2
=
sisestusN2
();
int
M
=
sisestusM
();
int
n
=
n1
+
n2
;
int
K1
[
n1
];
int
K2
[
n2
];
int
K
[
n
];
MassiivSisse
(
n1
,
n2
,
K1
,
K2
);
V
ä
ljastusAlgne
(
n1
,
n2
,
K1
,
K2
);
YhineMassiiv
(
n
,
n1
,
n2
,
K
,
K1
,
K2
);
Sortimine
(
n
,
K
);
V
ä
ljastus
(
M
,
n
,
K
);
return
0
;
}
int
sisestusN1
()
{
int
n1
;
printf
(
"Sisesta 1. massiivi liikmete arv n1"
);
scanf
(
"%d"
,
&
n1
);
return
n1
;
}
int
sisestusN2
()
{
int
n2
;
printf
(
"Sisesta 2. massiivi liikmete arv n2"
);
scanf
(
"%d"
,
&
n2
);
return
n2
;
}
int
sisestusM
()
{
int
M
;
printf
(
"Sisesta väljastatavate elementide arv M."
);
scanf
(
"%d"
,
&
M
);
return
M
;
}
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
//Massiivide sisselugemine
{
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K1
[
i
]);
}
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"Sisesta 2. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K2
[
i
]);
}
}
void
V
ä
ljastusAlgne
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
{
int
i
;
printf
(
"
\n
Sisestatud massiiv nr 1. on: "
);
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
printf
(
"%d "
,
K1
[
i
]);
}
printf
(
"
\n
Sisestatud massiiv nr 2. on: "
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"%d "
,
K2
[
i
]);
}
}
void
YhineMassiiv
(
int
n
,
int
n1
,
int
n2
,
int
K1
[],
int
K2
[],
int
K
[])
//K[n] moodustamine
{
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
K
[
i
]
=
K1
[
i
];
}
for
(
i
=
n1
;
i
<
n
;
i
++
)
{
K
[
i
]
=
K2
[
i
-
n1
];
}
}
void
Sortimine
(
int
n
,
int
K
[])
{
int
Vahetus
;
int
i
;
int
sorditud
=
0
;
while
(
sorditud
==
0
)
{
sorditud
=
1
;
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
{
if
(
K
[
i
]
>
K
[
i
+
1
])
{
Vahetus
=
K
[
i
];
K
[
i
]
=
K
[
i
+
1
];
K
[
i
+
1
]
=
Vahetus
;
sorditud
=
0
;
}
}
}
}
void
V
ä
ljastus
(
int
M
,
int
n
,
int
K
[])
{
int
i
;
printf
(
"
\n
%d elementi sorditud massiivist: "
,
M
);
for
(
i
=
0
;
i
<
M
&&
i
<
n
;
i
++
)
{
printf
(
"%d "
,
K
[
i
]);
}
printf
(
"
\n
"
);
}
#include <stdio.h>
// Prototüübid
int
sisestusN1
();
int
sisestusN2
();
int
sisestusM
();
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
void
Sortimine
(
int
,
int
[]);
void
V
ä
ljastus
(
int
,
int
,
int
[]);
int
main
(
void
)
{
int
n1
=
sisestusN1
();
int
n2
=
sisestusN2
();
int
M
=
sisestusM
();
int
n
=
n1
+
n2
;
int
K1
[
n1
];
int
K2
[
n2
];
int
K
[
n
];
MassiivSisse
(
n1
,
n2
,
K1
,
K2
);
V
ä
ljastusAlgne
(
n1
,
n2
,
K1
,
K2
);
YhineMassiiv
(
n
,
n1
,
n2
,
K
,
K1
,
K2
);
Sortimine
(
n
,
K
);
V
ä
ljastus
(
M
,
n
,
K
);
return
0
;
}
int
sisestusN1
()
{
int
n1
;
printf
(
"Sisesta 1. massiivi liikmete arv n1: "
);
scanf
(
"%d"
,
&
n1
);
return
n1
;
}
int
sisestusN2
()
{
int
n2
;
printf
(
"Sisesta 2. massiivi liikmete arv n2: "
);
scanf
(
"%d"
,
&
n2
);
return
n2
;
}
int
sisestusM
()
{
int
M
;
printf
(
"Sisesta väljastatavate elementide arv M: "
);
scanf
(
"%d"
,
&
M
);
return
M
;
}
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
{
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K1
[
i
]);
}
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"Sisesta 2. massiivi element nr %d: "
,
i
);
scanf
(
"%d"
,
&
K2
[
i
]);
}
}
void
V
ä
ljastusAlgne
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
{
int
i
;
printf
(
"
\n
Sisestatud massiiv nr 1. on: "
);
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
printf
(
"%d "
,
K1
[
i
]);
}
printf
(
"
\n
Sisestatud massiiv nr 2. on: "
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"%d "
,
K2
[
i
]);
}
}
void
YhineMassiiv
(
int
n
,
int
n1
,
int
n2
,
int
K
[],
int
K1
[],
int
K2
[])
{
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
K
[
i
]
=
K1
[
i
];
}
for
(
i
=
n1
;
i
<
n
;
i
++
)
{
K
[
i
]
=
K2
[
i
-
n1
];
}
}
void
Sortimine
(
int
n
,
int
K
[])
{
int
Vahetus
;
int
i
;
int
sorditud
=
0
;
while
(
sorditud
==
0
)
{
sorditud
=
1
;
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
{
if
(
K
[
i
]
>
K
[
i
+
1
])
{
Vahetus
=
K
[
i
];
K
[
i
]
=
K
[
i
+
1
];
K
[
i
+
1
]
=
Vahetus
;
sorditud
=
0
;
}
}
}
}
void
V
ä
ljastus
(
int
M
,
int
n
,
int
K
[])
{
int
i
;
printf
(
"
\n
%d elementi sorditud massiivist: "
,
M
);
for
(
i
=
0
;
i
<
M
&&
i
<
n
;
i
++
)
{
printf
(
"%d "
,
K
[
i
]);
}
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