Create program with one-dimension array Given an array of numbers. Find the value of the minimum element. If there are more than one element, then determine how many of them.
#include<iostream>
using namespace std;
int main()
{
unsigned int N;
cout << "Please, enter a size of array: ";
cin >> N;
int *arr = new int[N];
for (int i = 0; i<N; i++)
{
cout << "Enter a value for [" << i << "] element: ";
cin >> arr[i];
}
int minval = arr[0];
for (int i = 0; i<N; i++)
{
if (arr[i] < minval)
{
minval = arr[i];
}
}
int count = 0;
for (int i = 0; i<N; i++)
{
if (arr[i] == minval)
{
count++;
}
}
cout << "The value of minimum element is " << minval
<< "\nIt has " << count << " occurences in array";
delete[] arr;
}
Comments
Leave a comment