Advertisement
unitsuke

Problem 3. Categorize Numbers and Find Min / Max / Average

Sep 18th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             float[] intList = Console.ReadLine().Split(' ').Select(float.Parse).ToArray();
  14.             List<float> roundNumbers = new List<float>();
  15.             List<float> notRoundNumber = new List<float>();
  16.             for (int i = 0; i < intList.Length; i++)              
  17.             {
  18.                 if (intList[i] % 1 == 0)
  19.                 {
  20.                     roundNumbers.Add(intList[i]);
  21.                 }
  22.                 else
  23.                 {
  24.                     notRoundNumber.Add(intList[i]);
  25.                 }
  26.             }
  27.             Console.WriteLine("[{0}]->  min={1}, max={2}, sum={3}, avg={4:f2}", string.Join(", ", notRoundNumber), notRoundNumber.Min(), notRoundNumber.Max(), notRoundNumber.Sum(), notRoundNumber.Average());
  28.             Console.WriteLine("[{0}]->  min={1}, max={2}, sum={3}, avg={4:f2}", string.Join(", ", roundNumbers), roundNumbers.Min(), roundNumbers.Max(), roundNumbers.Sum(), roundNumbers.Average());
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement