Answer to Question #277827 in C++ for Ruba

Question #277827

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.

1
Expert's answer
2021-12-09T17:34:20-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog