Thy Minh Thy Minh -4 years ago 99
C# Question

Program generates 50 random numbers (between 1 to 10) and tells the amount of values that are smaller than 5 and bigger than 5 (C#)

Program generates 50 random numbers (between 1 to 10) and tells the amount of values that are smaller than 5 and bigger than 5 (C#)

Answer Source

You could do it like that:

Random r = new Random();
int n = 50;
int smaller_than_5 = 0;
int bigger_than_5 = 0;
double[] d = new double[n];
for (int i = 0; i < n; i++)
{
    d[i] = 1 + r.NextDouble() * 9;
    if (d[i] < 5) smaller_than_5++;
    else if (d[i] > 5) bigger_than_5++;
}

Hope this helps ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download