Другие языки программирования и технологии

Программирование на c++

Определить, находится ли число k в массиве M состоящем из 50 целых чисел. (c++)
Пожалуйста, помогите написать программу. Буду очень благодарен. Заранее спасибо!
#include <iostream>
#include <array>
#include <random>
#include <algorithm>
#include <iomanip>
using namespace std;
using array_50 = array<int, 50U>;
void fill(array_50& box) {
const uniform_int_distribution<> uid(1, 999);
random_device rd;
mt19937 gen(rd());
for (auto &item : box) item = uid(gen);
}
void show(const array_50& box) {
for (const auto value : box) cout << setw(4U) << value;
cout.put('\n');
}
bool find(const array_50& box, const int value) {
auto res = find(box.begin(), box.end(), value);
return res != box.end();
}
int main() {
array_50 box;
fill(box);
show(box);
cout << "Value: ";
int value;
cin >> value;
if (find(box, value)) cout << "Yes!";
else cout << "No!";
cout.put('\n');
system("pause");
}
Владимир Петренко
Владимир Петренко
76 403
Лучший ответ
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
using namespace std;
int main(){
srand(time(NULL));
int k, m[50];
bool f = false;
cout << "k = ", cin >> k;
for (int i = 0; i < 50; m[i] = rand() % 51, cout << setw(3) << m[i], m[i] == k? f = true : f = f,++i);
cout << endl << (f ? "Yes" : "No") << endl;
cin.ignore(), cin.get();
return 0;
}
Тахир Рузиев Большое спасибо!) Очень помогли!!!
if( k == M[ индекс ] ){
находится;
break;
}
for LEL=1 TO 50 DO if integer k is in array M then CAKE

PS:CAKE LIES!