Hi

double[] MyArray = new double[10];

I have 10 numbers and I get average of them.

But how can print out how many of the numbers that are smaller than average, and how many of the numbers that are larger than average?

tony75 10 Newbie Poster

Hi

double[] MyArray = new double[10];

I have 10 numbers and I get average of them.

But how can print out how many of the numbers that are smaller than average, and how many of the numbers that are larger than average?

tony75 10 Newbie Poster

Thanks Sir

I mean the users can specify an arbitrary number of integers. Then the program will calculate the average of the given numbers. At last, the program will print out how many of the numbers that are smaller than average, and how many of the numbers that are larger than average?

Actually I need to know how can print out how many of the numbers that are smaller than average, and how many of the numbers that are larger than average?

tony75 10 Newbie Poster

The code give me the minimum and maximam number

```
int min = arrNumbers[0];
int max = arrNumbers[0];
int sum = 0;
double average = 0;
for (int i = 0; i < n; i++)
{
sum += arrNumbers[i];
if (min > arrNumbers[i])
min = arrNumbers[i];
if (max < arrNumbers[i])
max = arrNumbers[i];
}
```

Bu I need to print out all nummber that are smaller and larger than average?

tinstaafl 1,176 Posting Maven

To print out the information, to the screen, not to an actual printer. You can use a temporary pop-up called Message Box, which will display your information until the user clicks and OK button. You can also put a Text Box or a Label on your form in which you can display the information until you change it in your program. If you meant an actual printer you could use the Printer Dialog, which is in your toolbox. It will depend on what your requirements are. Information on how to use these is linked to each one.

tony75 10 Newbie Poster

But I need the information print out in my textbox not message box?

Have you any idea about coden?

Edited by tony75 because: * wrong text *

tinstaafl 1,176 Posting Maven

ddanbe 2,724 Professional Procrastinator Featured Poster

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
double[] MyArray = new double[]{10,9,5,77,45,23,12,5,88,49};
double wrecked = MyArray.Average();
int lowerthanAv = 0, higherthanAv = 0;
for (int i = 0; i < MyArray.Length; i++)
{
if (MyArray[i] < wrecked)
lowerthanAv++;
else
higherthanAv++; // I do not take equal than av into acount here
}
Console.WriteLine("The average is: {0}", wrecked);
Console.WriteLine("Number lower than average: {0}", lowerthanAv);
Console.WriteLine("Number higher than average: {0}", higherthanAv);
Console.ReadLine();
}
}
}
```

I think the above code does what you like to do.

tinstaafl 1,176 Posting Maven

Here you go sorry for the confusion I think this gives you what you want.

```
int[] ArrNumbers = new int[] { 10, 9, 5, 77, 45, 23, 12, 5, 88, 49 };
int min = ArrNumbers.Min();
int max = ArrNumbers.Max();
double average = ArrNumbers.Average();
string higher = "", lower = "", equal = "";
for (int i = 0; i < ArrNumbers.Length - 1; i++)
{
if (ArrNumbers[i] < average)
{
lower = lower + Convert.ToString(ArrNumbers[i]) + " ";
}
else
{
if (ArrNumbers[i] > average)
{
higher = higher + Convert.ToString(ArrNumbers[i]) + " ";
}
else
{
equal = equal + Convert.ToString(ArrNumbers[i]) + " ";
}
}
}
textBox1.Lines = new string[] { "Minimum - " + min, "Maximum - " + max, "Average - " + average, "Lower - " + lower, "Higher - " + higher, "Equal - " + equal };
```

the output in the textbox is:

Minimum - 5

Maximum - 88

Average - 32.3

Lower - 10 9 5 23 12 5

Higher - 77 45 88

Equal -

Edited by tinstaafl

tony75 10 Newbie Poster

"I think the above code does what you like to do."

Yes Sir,Thats I mean Thank you very much again

Edited by tony75

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.