Возможный вариант в C++ #include <iostream> int main() { using namespace std; int N; cout << "Enter N: "; cin >> N; int num; int max = 1; int i; for (i = 0; i < N; ++i) { cout << "Enter #" << i + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) { max = num; break; } } for (int j = i + 1; j < N; ++j) { cout << "Enter #" << j + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) if (num > max) max = num; } if (max != 1) cout << "Max number div by 3 and don't end 9: " << max << endl; else cout << "No numbers div by 3 and don't end 9" << endl; return 0; }
#include <iostream>
int main()
{
using namespace std;
int N;
cout << "Enter N: ";
cin >> N;
int num;
int max = 1;
int i;
for (i = 0; i < N; ++i)
{
cout << "Enter #" << i + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
{
max = num;
break;
}
}
for (int j = i + 1; j < N; ++j)
{
cout << "Enter #" << j + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
if (num > max)
max = num;
}
if (max != 1)
cout << "Max number div by 3 and don't end 9: " << max << endl;
else
cout << "No numbers div by 3 and don't end 9" << endl;
return 0;
}
#include <algorithm>
#include <iostream>
#include <random>
#include <vector>
void fillVector(std::vector<int>&, int lowerBound, int upperBound);
void print(const std::vector<int>&);
int main() {
std::vector<int> vec { };
std::size_t size { 0 };
std::cout
<< "Please, enter the number of elements: ";
std::cin
>> size;
if (size < 1 || size > 1000) {
std::cerr
<< "The size must be in the range [1; 1000]" << std::endl;
return 1;
}
vec.resize(size);
fillVector(vec, 0, 100);
print(vec);
std::size_t changes { 0 };
for (std::size_t i { 0 }; i < vec.size() - 1; ++i) {
int tempValue { 0 };
for (std::size_t j { i + 1 }; j < vec.size(); ++j) {
if (vec.at(i) > vec.at(j)) {
tempValue = vec.at(i);
vec.at(i) = vec.at(j);
vec.at(j) = tempValue;
++changes;
}
}
}
print(vec);
std::cout
<< "Number of changes: " << changes << std::endl;
return 0;
}
void fillVector(std::vector<int>& vec, int lowerBound, int upperBound) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(lowerBound, upperBound);
int randomValue { };
for (auto& value : vec) {
while (true) {
randomValue = dist(gen);
if ( std::find( vec.begin(), vec.end(), randomValue) == vec.end() ){
value = randomValue;
break;
}
}
}
}
void print(const std::vector<int>& vec) {
for (const auto value : vec) {
std::cout
<< value << " ";
}
std::cout
<< std::endl;
}