#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int n;
int MIN;
int counter = 0;
cout << "Enter size of the array: ";
cin >> n;
int mass[n];
srand(time(NULL));
cout << "An array of the random elements:\n";
for (int i = 0; i < n; i++)
mass[i] = 1 + rand() % 4;
cout << mass[i];
cout << "\t";
}
MIN = mass[0];
for (int i = 1; i < n; i++)
MIN = MIN < mass[i] ? MIN : mass[i];
if (MIN == mass[i]) counter++;
cout << "\nNumber of elements that equal the min element of the array: " << counter - 1 << endl;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int n;
int MIN;
int counter = 0;
cout << "Enter size of the array: ";
cin >> n;
int mass[n];
srand(time(NULL));
cout << "An array of the random elements:\n";
for (int i = 0; i < n; i++)
{
mass[i] = 1 + rand() % 4;
cout << mass[i];
cout << "\t";
}
MIN = mass[0];
for (int i = 1; i < n; i++)
{
MIN = MIN < mass[i] ? MIN : mass[i];
}
for (int i = 0; i < n; i++)
{
if (MIN == mass[i]) counter++;
}
cout << "\nNumber of elements that equal the min element of the array: " << counter - 1 << endl;
}