-
Notifications
You must be signed in to change notification settings - Fork 27
/
controlwork$.c
185 lines (144 loc) · 3.52 KB
/
controlwork$.c
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "locale.h"
#include "memory.h"
#pragma warning(disable: 4996)
//Çàäàíèå íà îäíîìåðíûå ìàññèâû (¹2)
void array_merge(int A[], int B[], int n1, int n2) {
int l = 0, c = 0, f, N = n1 + n2;
int* arrm = (int*)malloc(sizeof(int) * 2000);
for (int i = 0; i < N; i++) {
arrm[i] = 0;
}
for (int i = 0; i < n1; i++) {
arrm[i] = A[i];
}
for (int j = n1; j < N; j++) {
arrm[j] = B[c];
c++;
}
for (int i = 0; i < N; i++) {
f = 0;
for (int j = 0; j < N; j++) {
if (arrm[i] < arrm[j]) {
c = arrm[i];
arrm[i] = arrm[j];
arrm[j] = c;
f = 1;
}
else {
f = 1;
}
}
if (f == 0) {
break;
}
}
for (int i = 0; i < N;) {
if (arrm[i] == arrm[i + 1]) {
i++;
}
else {
printf("%d ", arrm[i]);
i++;
l++;
}
}
printf("\nÈòîãîâàÿ äëèíà ìàññèâà áåç ïîâòîðåíèé: %d", l);
free(arrm);
}
int main1()
{
int A[1000];
int B[1000];
int n1 = 0, n2 = 0, minA = 0, maxA = 0, minB = 0, maxB = 0;
srand(time(NULL));
setlocale(LC_ALL, "Russian");
printf("Ââåäèòå æåëàåìóþ äëèíó ïåðâîãî è âòîðîãî ìàññèâà ñîîòâåòñâåííî: ");
scanf("%d %d", &n1, &n2);
printf("Ââåäèòå äèàïàçîí äëÿ ïåðâîãî ìàññèâà: ");
scanf("%d %d", &minA, &maxA);
printf("Ââåäèòå äèàïàçîí äëÿ âòîðîãî ìàññèâà: ");
scanf("%d %d", &minB, &maxB);
printf("Ìàññèâ A: ");
for (int i = 0; i < n1; i++) {
A[i] = minA + (double)rand() / RAND_MAX * (maxA - minA);
printf("%d ", A[i]);
}
printf("\n\nÌàññèâ B: ");
for (int i = 0; i < n2; i++) {
B[i] = minB + (double)rand() / RAND_MAX * (maxB - minB);
printf("%d ", B[i]);
}
printf("\n\nGreatful! Âàø ãîòîâûé ìàññèâ áåç ïîâòîðåíèé: ");
array_merge(A, B, n1, n2);
return 0;
}
//Çàäàíèå íà äâóìåðíûå ìàññèâû (¹2)
int main2() {
int m = 0, n = 0, x = 0, c = 0, count = 0;
int minA = 0, maxA = 0, maxS = 0;
double mid = 0;
setlocale(LC_ALL, "Russian");
srand(time(NULL));
printf("Çàäàéòå ðàçìåðíîñòü ìàññèâà, ãäå m ñòðîê x n ñòîëáöîâ: ");
scanf("%d %d", &m, &n);
printf("Ââåäèòå ìèíèìàëüíóþ è ìàêñèìàëüíóþ ãðàíèöó äèàïàçîíà äëÿ çàïîëíåíèÿ ìàññèâà: ");
scanf("%d %d", &minA, &maxA);
int** A = (int**)malloc(sizeof(int*) * n);
for (int i = 0; i < n; i++) {
A[i] = (int*)malloc(sizeof(int) * m);
}
printf("Ñãåíåðèðîâàííûé ìàññèâ: \n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
x = minA + (double)rand() / RAND_MAX * (maxA - minA);
A[i][j] = x;
c += x;
printf("%d ", A[i][j]);
}
printf("\n");
}
mid = c / (m * n);
printf("\n\nÑðåäíåå çíà÷åíèå ýëåìåíòîâ ìàòðèöû: %lf \n\n", mid);
//Òðàíñïîíèðîâàíèå ìàòðèöû
int** B = (int**)malloc(sizeof(int*) * m); //Âñïîìîãàòåëüíàÿ matrix
for (int i = 0; i < m; i++) {
B[i] = (int*)malloc(sizeof(int) * n);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
B[j][i] = A[i][j];
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", B[i][j]);
}
printf("\n");
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (B[i][j] > mid) {
count++;
printf("%d ", count);
}
}
if (count > maxS) {
maxS = i+1;
}
count = 0;
printf("\n");
}
for (int i = 0; i < n; i++) {
free(B[i]);
}
free(B);
for (int i = 0; i < n; i++) {
free(A[i]);
}
free(A);
printf("\n\nÑòðîêà ñ ïðåâîñõîäÿùèì êîëè÷åñòâîì ýëåìåíòîâ, áîëüøèõ mid çíà÷åíèé ìàòðèöû: %d ", maxS);
return 0;
}