Другие языки программирования и технологии
Помогите создать программу в с++
Дан массив из N натуральных чисел. Создать массив из чётных чисел этого массива. Если таких чисел нет, то вывести сообщение об этом факте. Написать программу в С++ только!! Помогите пожалуйста
#include <iostream>
#include <random>
using namespace std;
void fill(unsigned* box, const size_t n) {
uniform_int_distribution<unsigned> uid(10, 99);
mt19937 gen{ random_device()() };
for (auto i = 0U; i < n; ++i) box[i] = uid(gen);
}
size_t even(unsigned* b, unsigned* a, const size_t n) {
auto j = 0U;
for (auto i = 0U; i < n; ++i) if (~a[i] & 1) b[j++] = a[i];
return j;
}
void show(unsigned* box, const size_t n) {
for (auto i = 0U; i < n; ++i) cout << ' ' << box[i];
cout.put('\n');
}
void nf() { cout << " Not found!\n"; }
int main() {
const auto limit = 1024U;
unsigned a[limit], b[limit];
cout << " n: ";
size_t n;
cin >> n;
if (!n || n > limit) exit(0);
fill(a, n);
show(a, n);
auto m = even(b, a, n);
m? show(b, m) : nf();
system("pause");
}
#include <random>
using namespace std;
void fill(unsigned* box, const size_t n) {
uniform_int_distribution<unsigned> uid(10, 99);
mt19937 gen{ random_device()() };
for (auto i = 0U; i < n; ++i) box[i] = uid(gen);
}
size_t even(unsigned* b, unsigned* a, const size_t n) {
auto j = 0U;
for (auto i = 0U; i < n; ++i) if (~a[i] & 1) b[j++] = a[i];
return j;
}
void show(unsigned* box, const size_t n) {
for (auto i = 0U; i < n; ++i) cout << ' ' << box[i];
cout.put('\n');
}
void nf() { cout << " Not found!\n"; }
int main() {
const auto limit = 1024U;
unsigned a[limit], b[limit];
cout << " n: ";
size_t n;
cin >> n;
if (!n || n > limit) exit(0);
fill(a, n);
show(a, n);
auto m = even(b, a, n);
m? show(b, m) : nf();
system("pause");
}
Ок...
#include < iostream >
#include < vector >
#include < random >
#include < algorithm >
#include < iterator >
#include < functional >
int main() {
const size_t N = 10;
std::vector< int > a(N);
std::mt19937 gen { std::random_device()() };
std::uniform_int_distribution<> dist(-10,10);
std::generate(a.begin(), a.end(), std::bind(dist,gen));
std::cout<<"--- before ---\n";
std::copy(a.begin(), a.end(), std::ostream_iterator< int >(std::cout, " "));
a.erase(std::remove_if(a.begin(), a.end(), std::bind2nd(std::modulus< int >(),2)), a.end());
std::cout<<"\n--- after ---\n";
if (!a.empty())
std::copy(a.begin(), a.end(), std::ostream_iterator< int >(std::cout, " "));
else std::cout << "not found!\n";
return 0;
}
https://www.ideone.com/IkxFZ0
#include < iostream >
#include < vector >
#include < random >
#include < algorithm >
#include < iterator >
#include < functional >
int main() {
const size_t N = 10;
std::vector< int > a(N);
std::mt19937 gen { std::random_device()() };
std::uniform_int_distribution<> dist(-10,10);
std::generate(a.begin(), a.end(), std::bind(dist,gen));
std::cout<<"--- before ---\n";
std::copy(a.begin(), a.end(), std::ostream_iterator< int >(std::cout, " "));
a.erase(std::remove_if(a.begin(), a.end(), std::bind2nd(std::modulus< int >(),2)), a.end());
std::cout<<"\n--- after ---\n";
if (!a.empty())
std::copy(a.begin(), a.end(), std::ostream_iterator< int >(std::cout, " "));
else std::cout << "not found!\n";
return 0;
}
https://www.ideone.com/IkxFZ0
Похожие вопросы
- помогите создать программу в паскале
- Помогите пожалуйста создать программу на Паскале. Заранее всем благодарен
- Помогите пожалуйста создать программу "Таймер" на СИ. Заранее всем благодарен!)
- пожалуйста, напишите мне программу этого вопроса в C ++.пожалуйста помогите. Создать динамический массив из N чисел.
- Нужно создать программу в Pascal ABC.NET
- Помогите написать программу со switch в СИ
- Вот мне интересно, с помощью какой программы - можно создать ПРОГРАММУ? :D
- Создать программу(описание ниже)
- какую выб хотели создать программу
- Как создать программу на языке c++