-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwm.cpp
More file actions
104 lines (82 loc) · 2.33 KB
/
pwm.cpp
File metadata and controls
104 lines (82 loc) · 2.33 KB
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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <windows.h>
using namespace std;
int main() {
SetConsoleOutputCP(65001);
short * a = new short[10];
srand(time(0));
cout << "Исходный массив А: ";
for(short i = 0; i < 10; i++) {
a[i] = rand() % 101 - 50;
cout << a[i] << " ";
}
cout << endl << endl;
short minIndex = 0;
for(short i = 1; i < 10; i++) {
if(a[i] < a[minIndex]) {
minIndex = i;
}
}
cout << "Минимальный элемент: " << a[minIndex] << " (индекс " << minIndex << ")" << endl;
short * b = new short[9];
short j = 0;
for (short i = 0; i < 10; i++) {
if (i != minIndex) {
b[j] = a[i];
j++;
}
}
cout << "Массив B (после удаления): ";
for(short j = 0; j < 9; j++) {
cout << b[j] << " ";
}
cout << endl << endl;
unsigned short M;
cout << "Введите M (сколько элементов добавить): ";
cin >> M;
short * c = new short[9 + M];
memmove(c, b, 9 * sizeof(short));
for (int i = 9; i < 9 + M; i++) {
c[i] = rand() % 101 - 50;
}
cout << "Массив C (после вставки): ";
for (int i = 0; i < 9 + M; i++) {
cout << c[i] << " ";
}
cout << endl << endl;
unsigned short K;
cout << "Введите K (на сколько сдвинуть вправо): ";
cin >> K;
for (unsigned short j = 0; j < K; j++) {
short temp = a[9];
for (short i = 9; i > 0; i--) {
a[i] = a[i - 1];
}
a[0] = temp;
}
cout << "Массив А (после сдвига): ";
for(short j = 0; j < 10; j++){
cout << a[j] << " ";
}
cout << endl << endl;
short indexFound = -1;
for (short i = 0; i < 10; i++) {
if (a[i] < 0) {
indexFound = i;
break;
}
}
if (indexFound != -1) {
cout << "Первый отрицательный элемент: " << a[indexFound]
<< " (индекс " << indexFound << ")" << endl;
} else {
cout << "Отрицательных элементов нет" << endl;
}
delete[] a;
delete[] b;
delete[] c;
return 0;
}