Last active
August 29, 2015 14:20
-
-
Save EBojilova/5a2d8f2b26f130bfe3a5 to your computer and use it in GitHub Desktop.
03. Categorize Numbers and Find Min / Max / Average
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
class CategorizeNumbers | |
{ | |
static void Main(string[] args) | |
{ | |
double[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), s => double.Parse(s)); | |
var floatNums = nums.Where(i => i != (int)i); | |
var roundNums = nums.Where(i => i == (int)i); | |
if (floatNums.Count()>0) | |
{ | |
Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:F2}", string.Join(" ", floatNums), floatNums.Min(), floatNums.Max(), floatNums.Sum(), floatNums.Average()); | |
Console.WriteLine(); | |
} | |
if (roundNums.Count()>0) | |
{ | |
Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:F2}", string.Join(" ", roundNums), roundNums.Min(), roundNums.Max(), roundNums.Sum(), roundNums.Average()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment