Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Samson_Act
- {
- static void Main(string[] args)
- {
- List<int> nums = new List<int>();
- int input;
- Console.WriteLine("Enter numbers one by one (enter 0 to finish):");
- do
- {
- Console.Write("Enter a number: ");
- string userInput = Console.ReadLine();
- if (int.TryParse(userInput, out input))
- {
- if (input != 0)
- {
- nums.Add(input);
- }
- }
- else
- {
- Console.WriteLine("Invalid input. Please enter a valid number.");
- input = -1;
- }
- } while (input != 0);
- if (nums.Count > 0)
- {
- int smallest = nums[0];
- int largest = nums[0];
- foreach (int num in nums)
- {
- if (num < smallest)
- smallest = num;
- if (num > largest)
- largest = num;
- }
- Console.WriteLine($"\nSmallest number: {smallest}");
- Console.WriteLine($"Largest number: {largest}");
- }
- else
- {
- Console.WriteLine("\nNo numbers were entered.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment