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]
#include <stdio.h>
* Massiivide elemendid liidetakse, moodustatakse
* uus massiiv K[n].
// Prototüübid
* salvestatakse uuele id massiivile
int
sisestusN1
();
* Väljastatakse minimaalsete elementide massiiv,
int
sisestusN2
();
* minimaalselt 3 alamprogrammi. */
int
sisestusM
();
#include <stdio.h>
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
//Prototüübid
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
int
sisestusN1
();
void
Sortimine
(
int
,
int
[]);
int
sisestusN2
();
void
V
ä
ljastus
(
int
,
int
,
int
[]);
int
sisestusM
();
void
MassiivSisse
(
int
,
int
,
int
[],
int
[]);
int
main
(
void
)
void
V
ä
ljastusAlgne
(
int
,
int
,
int
[],
int
[]);
{
void
YhineMassiiv
(
int
,
int
,
int
,
int
[],
int
[],
int
[]);
int
n1
=
sisestusN1
();
void
Sortimine
(
int
,
int
[]);
int
n2
=
sisestusN2
();
void
V
ä
ljastus
(
int
,
int
,
int
[]);
int
M
=
sisestusM
();
int
n
=
n1
+
n2
;
int
main
(
void
)
int
K1
[
n1
];
{
int
K2
[
n2
];
int
n1
=
sisestusN1
();
int
K
[
n
];
int
n2
=
sisestusN2
();
int
M
=
sisestusM
();
MassiivSisse
(
n1
,
n2
,
K1
,
K2
);
int
n
=
n1
+
n2
;
V
ä
ljastusAlgne
(
n1
,
n2
,
K1
,
K2
);
int
K1
[
n1
];
YhineMassiiv
(
n
,
n1
,
n2
,
K
,
K1
,
K2
);
int
K2
[
n2
];
Sortimine
(
n
,
K
);
int
K
[
n
];
V
ä
ljastus
(
M
,
n
,
K
);
MassiivSisse
(
n1
,
n2
,
K1
,
K2
);
return
0
;
V
ä
ljastusAlgne
(
n1
,
n2
,
K1
,
K2
);
}
YhineMassiiv
(
n
,
n1
,
n2
,
K
,
K1
,
K2
);
Sortimine
(
n
,
K
);
int
sisestusN1
()
V
ä
ljastus
(
M
,
n
,
K
);
{
int
n1
;
return
0
;
printf
(
"Sisesta 1. massiivi liikmete arv n1: "
);
}
scanf
(
"%d"
,
&
n1
);
return
n1
;
int
sisestusN1
()
}
{
int
n1
;
int
sisestusN2
()
printf
(
"Sisesta 1. massiivi liikmete arv n1"
);
{
scanf
(
"%d"
,
&
n1
);
int
n2
;
return
n1
;
printf
(
"Sisesta 2. massiivi liikmete arv n2: "
);
}
scanf
(
"%d"
,
&
n2
);
int
sisestusN2
()
return
n2
;
{
}
int
n2
;
printf
(
"Sisesta 2. massiivi liikmete arv n2"
);
int
sisestusM
()
scanf
(
"%d"
,
&
n2
);
{
return
n2
;
int
M
;
}
printf
(
"Sisesta väljastatavate elementide arv M: "
);
int
sisestusM
()
scanf
(
"%d"
,
&
M
);
{
return
M
;
int
M
;
}
printf
(
"Sisesta väljastatavate elementide arv M."
);
scanf
(
"%d"
,
&
M
);
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
return
M
;
{
}
int
i
;
for
(
i
=
0
;
i
<
n1
;
i
++
)
void
MassiivSisse
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
//Massiivide sisselugemine
{
{
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
int
i
;
scanf
(
"%d"
,
&
K1
[
i
]);
for
(
i
=
0
;
i
<
n1
;
i
++
)
}
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
printf
(
"Sisesta 1. massiivi element nr %d: "
,
i
);
{
scanf
(
"%d"
,
&
K1
[
i
]);
printf
(
"Sisesta 2. massiivi element nr %d: "
,
i
);
}
scanf
(
"%d"
,
&
K2
[
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: "
);
void
V
ä
ljastusAlgne
(
int
n1
,
int
n2
,
int
K1
[],
int
K2
[])
for
(
i
=
0
;
i
<
n1
;
i
++
)
{
{
int
i
;
printf
(
"%d "
,
K1
[
i
]);
printf
(
"
\n
Sisestatud massiiv nr 1. on: "
);
}
for
(
i
=
0
;
i
<
n1
;
i
++
)
printf
(
"
\n
Sisestatud massiiv nr 2. on: "
);
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
printf
(
"%d "
,
K1
[
i
]);
{
}
printf
(
"%d "
,
K2
[
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
++
)
void
YhineMassiiv
(
int
n
,
int
n1
,
int
n2
,
int
K1
[],
int
K2
[],
int
K
[])
//K[n] moodustamine
{
{
K
[
i
]
=
K1
[
i
];
int
i
;
}
for
(
i
=
0
;
i
<
n1
;
i
++
)
for
(
i
=
n1
;
i
<
n
;
i
++
)
{
{
K
[
i
]
=
K1
[
i
];
K
[
i
]
=
K2
[
i
-
n1
];
}
}
for
(
i
=
n1
;
i
<
n
;
i
++
)
}
{
K
[
i
]
=
K2
[
i
-
n1
];
void
Sortimine
(
int
n
,
int
K
[])
}
{
}
int
Vahetus
;
int
i
;
void
Sortimine
(
int
n
,
int
K
[])
int
sorditud
=
0
;
{
int
Vahetus
;
while
(
sorditud
==
0
)
int
i
;
{
int
sorditud
=
0
;
sorditud
=
1
;
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
while
(
sorditud
==
0
)
{
{
if
(
K
[
i
]
>
K
[
i
+
1
])
sorditud
=
1
;
{
for
(
i
=
0
;
i
<
(
n
-
1
);
i
++
)
Vahetus
=
K
[
i
];
{
K
[
i
]
=
K
[
i
+
1
];
if
(
K
[
i
]
>
K
[
i
+
1
])
K
[
i
+
1
]
=
Vahetus
;
{
sorditud
=
0
;
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
++
)
void
V
ä
ljastus
(
int
M
,
int
n
,
int
K
[])
{
{
printf
(
"%d "
,
K
[
i
]);
int
i
;
}
printf
(
"
\n
%d elementi sorditud massiivist: "
,
M
);
printf
(
"
\n
"
);
for
(
i
=
0
;
i
<
M
&&
i
<
n
;
i
++
)
}
{
\ No newline at end of file
printf
(
"%d "
,
K
[
i
]);
}
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