-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab №5
89 lines (87 loc) · 2.08 KB
/
Lab №5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
system("chcp 1251>null");
int n,m;
do {
cout <<"[АНТИНЕРОЗУМНИЙ КОРИСТУВАЧ]Підказка:\n\t n повинно бути не більше 300\n\t m повинно бути не більше 200";
cout << "\n[АНТИНЕРОЗУМНИЙ КОРИСТУВАЧ] Введіть розмірність масиву n =>> ";
cin >>n;
cout << "\n[АНТИНЕРОЗУМНИЙ КОРИСТУВАЧ] Введіть розмірність масиву m =>> ";
cin >>m;
}while (n>300 && m>200);
int a[n];
int b[m];
srand(time(NULL));
for (int e=0; e<n; e++){
a[e] = rand()% 300;
for(int i=0;i<n-1;i++){
int min_i=i;
for(int j=i+1;j<n;j++){
if(a[j]<a[min_i]){
min_i=j;
}
}
int temp =a[i];
a[i]=a[min_i];
a[min_i]=temp;
}
cout<<"n="<<a[e]<<endl;
}
for (int e=0; e<m; e++){
b[e]= rand()% 200;
for(int i=0;i<n-1;i++){
int min_i=i;
for(int j=i+1;j<n;j++){
if(b[j]<b[min_i]){
min_i=j;
}
}
int temp =b[i];
b[i]=b[min_i];
b[min_i]=temp;
}
cout<<"\tm="<<a[e]<<endl;
}
int i,j,k,l=n+m;
int c[l];
i=n-1;j=m-1;k=-1;
while((i>=0)&&(j>=0))
if(a[i]>b[j])
{
k++;
c[k]=a[i];
i--;
}
else
{
k++;
c[k]=b[j];
j--;
}
if(i<0)
{
for(i=j;i>=0;i--)
{
k++;
c[k]=b[i];
}
}
else
{
for(j=i;j>=0;j--)
{
k++;
c[k]=a[j];
}
}
for(i=0;i<l;i++)
{
cout << "k="<< c[i] <<endl;
}
}