Skip to content

Instantly share code, notes, and snippets.

@EBojilova
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EBojilova/5a2d8f2b26f130bfe3a5 to your computer and use it in GitHub Desktop.
Save EBojilova/5a2d8f2b26f130bfe3a5 to your computer and use it in GitHub Desktop.
03. Categorize Numbers and Find Min / Max / Average
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