Specify an array of 10 elements using a random number generator.
August 22, 2021 | education
| Specify an array of 10 elements using a random number generator. Replace all positive elements with the maximum. Display the original and modified arrays.
#include <windows.h>
#include <iostream>
#include <ctime>
using namespace std;
void main ()
{
SetConsoleCP (1251);
SetConsoleOutputCP (1251);
srand (time (NULL));
int const N = 10;
int max = 0;
int mas [N];
cout << “Source array:” << endl;
for (int i = 0; i <N; i ++)
{
mas [i] = rand ()% 25 – 10;
cout << mas [i] << “”;
if (max <mas [i])
max = mas [i];
}
for (int i = 0; i <N; i ++)
if (mas [i]> 0)
mas [i] = max;
cout << endl << “New array:” << endl;
for (int i = 0; i <N; i ++)
{
cout << mas [i] << “”;
}
system (“pause”);
}
One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.