Answer to Question #253033 in C# for Israel

Question #253033

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.



1
Expert's answer
2021-10-20T05:23:16-0400
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();
        }


    }
}

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
APPROVED BY CLIENTS