Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Program
- {
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- RandomGenerator();
- }
- private static void RandomGenerator()
- {
- Random rand = new Random();
- List<int> randomNumbers = new List<int>();
- for (int i = 0; i < 113; i++)
- {
- randomNumbers.Add(rand.Next(222, 666));
- }
- Console.WriteLine(string.Join(" ", randomNumbers));
- Console.WriteLine();
- SmallestOdd(randomNumbers);
- }
- private static void SmallestOdd(List<int> list)
- {
- int minNum = int.MaxValue;
- int index = 0;
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i] % 2 != 0)
- {
- if (list[i] < minNum)
- {
- minNum = list[i];
- }
- }
- }
- if (list.Contains(minNum))
- {
- index = list.IndexOf(minNum);
- }
- Console.WriteLine($"Smallest odd number in the list is: {minNum} at index {index}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement