Skip to content

Commit 1bace09

Browse files
committed
Create main.cpp
1 parent aab88e3 commit 1bace09

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

cpp_homework_24/main.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// main.cpp
3+
// cpp_homework_24
4+
//
5+
// Created by Mark Semenov on 11.07.2022.
6+
//
7+
8+
#include <iostream>
9+
#include <algorithm>
10+
using namespace std;
11+
12+
int main(int argc, const char * argv[]) {
13+
//Task 1
14+
const int s = 10;
15+
int n[s] = {};
16+
17+
srand(time(0));
18+
rand();
19+
20+
for (int i = 0; i < s; i++) {
21+
n[i] = rand();
22+
cout << n[i] << " ";
23+
}
24+
cout << "\n";
25+
reverse(n, n + s);
26+
27+
for (int i = 0; i < s; i++) {
28+
cout << n[i] << " ";
29+
}
30+
cout << "\n\n";
31+
32+
//Task 2
33+
const int s = 5, s1 = 10;
34+
int n[s] = {}, n1[s] = {}, n2[s1] = {};
35+
36+
cout << "First array: ";
37+
for (int i = 0; i < s; i++) {
38+
n[i] = rand();
39+
cout << n[i] << " ";
40+
}
41+
cout << "\n";
42+
cout << "Second array: ";
43+
for (int i = 0; i < s; i++) {
44+
n1[i] = rand();
45+
cout << n1[i] << " ";
46+
}
47+
for (int i = 0, j = 0; i < s1; i += 2, j++) {
48+
n2[i] = n[j];
49+
}
50+
for (int i = 1, j = 0; i < s1; i += 2, j++) {
51+
n2[i] = n1[j];
52+
}
53+
cout << "\n";
54+
cout << "Third array: ";
55+
for (int i = 0; i < s1; i++) {
56+
cout << n2[i] << " ";
57+
}
58+
cout << "\n\n";
59+
60+
//Task 3
61+
const int s = 20;
62+
int n[s] = {}, nr[s] = {}, n1 = 0;
63+
64+
for (int i = 0; i < s; i++) {
65+
n[i] = rand() % 201 - 100;
66+
cout << n[i] << " ";
67+
}
68+
cout << "\n";
69+
for (int i = 0; i < s; i++) {
70+
if (n[i] > 0) {
71+
nr[n] = n[i];
72+
n1++;
73+
}
74+
}
75+
for (int i = 0; i < s; i++) {
76+
if (n[i] == 0) {
77+
nr[n] = n[i];
78+
n1++;
79+
}
80+
}
81+
for (int i = 0; i < s; i++) {
82+
if (n[i] < 0) {
83+
nr[n] = n[i];
84+
n1++;
85+
}
86+
}
87+
for (int i = 0; i < s; i++) {
88+
cout << nr[i] << " ";
89+
}
90+
cout << "\n";
91+
}

0 commit comments

Comments
 (0)