Write a program that generates 1000 random numbers between 0 and 100 000. Display the number of odd values generated as well as the smallest and the largest values. Output should be displayed in a windows message box.
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
Console.WriteLine("The number of odd values generated: ");
int min = int.MaxValue;
int max = int.MinValue;
for (int i = 0; i < 1000; i++) {
int number = rnd.Next(0, 100001);
if (number % 2 == 1) {
Console.Write("{0} ",number);
if (number < min) {
min = number;
}
if (number > max)
{
max = number;
}
}
}
Console.WriteLine("\n\nThe smallest value: {0}", min);
Console.WriteLine("The largest value: {0}", max);
Console.ReadLine();
}
}
}
Comments
Leave a comment