Advertisement
elena1234

Numbers

Oct 21st, 2020 (edited)
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Numbers
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<int> listOfNumbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13.             double averageNum = listOfNumbers.Average();
  14.             var newListNumsGreaterThanAverage = listOfNumbers.Where(x => x > averageNum).ToList();
  15.             var newListDescending = newListNumsGreaterThanAverage.OrderByDescending(x => x).ToList();
  16.  
  17.             if (newListDescending.Count == 0)
  18.             {
  19.                 Console.WriteLine($"No");
  20.             }
  21.  
  22.             else
  23.             {
  24.                 List<int> result= newListDescending.Take(5).ToList();
  25.                 Console.WriteLine(string.Join(" ",result));
  26.             }
  27.  
  28.         }
  29.  
  30.      }
  31.  
  32.     }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement