kirililchev3

Square numbers - Math.sqrt

Jun 9th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06_Square_Numbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> number = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.             List<int> squares = new List<int>();
  16.             for (int i = 0; i < number.Count; i++)
  17.             {
  18.                 int curr = number[i];
  19.  
  20.                 double square = Math.Sqrt(curr);
  21.                 int whole = (int)square;
  22.  
  23.                 if (square == whole)
  24.                 {
  25.                     squares.Add(curr);
  26.                 }
  27.             }
  28.             squares.Sort();
  29.             squares.Reverse();
  30.             Console.WriteLine(string.Join(" ", squares));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment