Удалить elements.cpp
This commit is contained in:
64
elements.cpp
64
elements.cpp
@@ -1,64 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <ctime>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
setlocale(0, "");
|
|
||||||
srand(time(0));
|
|
||||||
|
|
||||||
const int SiZE = 15;
|
|
||||||
int arr[SiZE];
|
|
||||||
|
|
||||||
for (int i = 0; i < SiZE; i++) {
|
|
||||||
arr[i] = rand() % 21 - 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Масив: ";
|
|
||||||
for (int i = 0; i < SiZE; i++) {
|
|
||||||
cout << arr[i] << " ";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
int third = 0;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < SiZE; i++) {
|
|
||||||
if (arr[i] > 0) {
|
|
||||||
count++;
|
|
||||||
if (count == 3) {
|
|
||||||
third = arr[i];
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int last = 0;
|
|
||||||
bool found2 = false;
|
|
||||||
|
|
||||||
for (int i = SiZE - 1; i >= 0; i--) {
|
|
||||||
if (arr[i] < 0) {
|
|
||||||
last = arr[i];
|
|
||||||
found2 = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
|
||||||
cout << "Третiй додатний елемент: " << third << endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cout << "Третiй додатний елемент не знайдено" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found2) {
|
|
||||||
cout << "Останнiй вiд'ємний елемент: " << last << endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cout << "Останнiй вiд'ємний елемент не знайдено" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user