Ю
ЮрийПрп
Здравсвуйте все,
есть програмный код(C++),он работает ,но остался один вопрос :
после генератора случайных чисел есть повторяющиеся значения ,однако на вывод идёт только первое число,
как сделать что бы вышли все значения (если конечно таковые имеются)
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
const int MAX = 100;
int result[MAX];
bool found = false;
int search = 0;
int criterion = 0;
//initialize the random number generator
srand(time(NULL));
for (int index = 0; index < MAX; index++) {
result[index] = rand() % 200;
}
cout << "The result are: " << endl;
for (int index = 0; index < MAX; index++)
cout << result[index] << ' ';
cout << endl;
cout << "Search for what? ";
cin >> criterion;
while ((search < MAX) && (found == false)) {
if (result[search] == criterion)
found = true;
else
search++;
}
if (found == true)
cout << "The value of " << criterion << " is located at the position " << search + 1<<endl;
else
cout << "The value of " << criterion << " was not found. " << endl;
return 0;
}
Заранее благодарен,Юрий.
есть програмный код(C++),он работает ,но остался один вопрос :
после генератора случайных чисел есть повторяющиеся значения ,однако на вывод идёт только первое число,
как сделать что бы вышли все значения (если конечно таковые имеются)
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
const int MAX = 100;
int result[MAX];
bool found = false;
int search = 0;
int criterion = 0;
//initialize the random number generator
srand(time(NULL));
for (int index = 0; index < MAX; index++) {
result[index] = rand() % 200;
}
cout << "The result are: " << endl;
for (int index = 0; index < MAX; index++)
cout << result[index] << ' ';
cout << endl;
cout << "Search for what? ";
cin >> criterion;
while ((search < MAX) && (found == false)) {
if (result[search] == criterion)
found = true;
else
search++;
}
if (found == true)
cout << "The value of " << criterion << " is located at the position " << search + 1<<endl;
else
cout << "The value of " << criterion << " was not found. " << endl;
return 0;
}
Заранее благодарен,Юрий.