#### Bratanov

##### New member

- Joined
- Feb 23, 2021

- Messages
- 1

- Programming Experience
- Beginner

Hey guys I'm currently working on a code I have to do for school. It goes: A series of n integers is given. Write a console application that finds and displays the smallest

and the largest number in the console and how many times those two numbers occur in it.

I have managed to do the part where it shows you the smallest and biggest number in the array, entered by the user. However, the second part is not working out and I have tried many solutions but still cannot manage to do it. I don't understand how to make the program measure how many times the largest and smallest numbers occur throughout the array.

Here is what I came up with. It gives you the smallest and biggest numbers but fails to measure how many times each of them occurs. Any help would be appreciated.

and the largest number in the console and how many times those two numbers occur in it.

I have managed to do the part where it shows you the smallest and biggest number in the array, entered by the user. However, the second part is not working out and I have tried many solutions but still cannot manage to do it. I don't understand how to make the program measure how many times the largest and smallest numbers occur throughout the array.

Here is what I came up with. It gives you the smallest and biggest numbers but fails to measure how many times each of them occurs. Any help would be appreciated.

C#:

```
using System;
class MainClass {
public static void Main (string[] args) {
int Count1 = 0;
int Count2 = 0;
string[] numbers;
int min=int.MaxValue;
int max=int.MinValue;
Console.Write("How many elements are there in the array:");
int element = int.Parse(Console.ReadLine());
int[] intNumbers=new int[element];
for(int i = 0; i < element; i ++)
{
Console.WriteLine($"The element {i} -");
intNumbers = int.Parse(Console.ReadLine());
}
for (int i = 0; i < element; i++)
{
if(intNumbers < min)
{
min = intNumbers;
}
if(min == intNumbers)
{
Count1++;
}
}
for(int j = 0; j < element; j++)
{
if(intNumbers[j] > max)
{
max = intNumbers[j];
}
if(max == intNumbers[j])
{
Count2++;
}
}
Console.WriteLine("The smallest number is {0}",min);
Console.WriteLine("The largest number is {0}",max);
Console.WriteLine("The smallest number occurs:" + Count1 + "times.");
Console.WriteLine("The largest number occurs:" + Count2 + "times.");
}
}
```

Last edited by a moderator: