Advertisement
NastySwipy

Progr-Fundamentals-Lists - 06. Square Numbers

Apr 13th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _06a_Lists_Lab
  5. {
  6.     class Lists_Lab
  7.     {
  8.       static void Main(string[] args)
  9.         {
  10.             List<int> numList = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  11.             List<int> squareNumbers = new List<int>();
  12.  
  13.             for (int i = 0; i < numList.Count; i++)
  14.             {
  15.                 if (Math.Sqrt(numList[i]) == (int)Math.Sqrt(numList[i]))
  16.                 {
  17.                     squareNumbers.Add(numList[i]);
  18.                 }
  19.             }
  20.             squareNumbers.Sort((a, b) => b.CompareTo(a));
  21.             Console.WriteLine(string.Join(" ", squareNumbers));
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement