Advertisement
desislava_topuzakova

min and max number

Jun 7th, 2020
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AlgorithmsOverStructureData
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             List<int> numbers = input.Split(" ").Select(int.Parse).ToList();
  13.             //2 4 1 6 7
  14.             int min = int.MaxValue; //numbers[0]
  15.             int max = int.MinValue;
  16.             foreach(int number in numbers)
  17.             {
  18.                 if(number < min)
  19.                 {
  20.                     min = number;
  21.                 }
  22.  
  23.                 if(number > max)
  24.                 {
  25.                     max = number;
  26.                 }
  27.             }
  28.  
  29.             Console.WriteLine("Min: " + min);
  30.             Console.WriteLine("Max: " + max);
  31.  
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement