stefan1919

Categorize Numbers and Find Min / Max / Average

Sep 8th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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 ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             string[] help = input.Split(' ');
  15.             float[] arrayInput = new float[help.Length];
  16.             List<float> output = new List<float>();
  17.             List<float> anotherOutput = new List<float>();
  18.             for (int i = 0; i < arrayInput.Length; i++)
  19.             {
  20.                
  21.                 arrayInput[i] = float.Parse(help[i]);
  22.             }
  23.             for (int i = 0; i < arrayInput.Length; i++)
  24.             {
  25.                 if (arrayInput[i] > (int)(arrayInput[i]))
  26.                 {
  27.                     output.Add(arrayInput[i]);
  28.                 }
  29.                 else
  30.                 {
  31.                     anotherOutput.Add(arrayInput[i]);
  32.                 }
  33.             }
  34.             Console.WriteLine("[{0}] -> min:{1}, max:{2}, sum:{3}, avg:{4}", string.Join(" ", output), output.Min(), output.Max(), output.Sum(), String.Format("{0:0.00}", output.Average()));
  35.             Console.WriteLine();
  36.             Console.WriteLine("[{0}] -> min:{1}, max:{2}, sum:{3}, avg:{4}", string.Join(" ", anotherOutput), anotherOutput.Min(), anotherOutput.Max(), anotherOutput.Sum(), String.Format("{0:0.00}", anotherOutput.Average()));
  37.             }
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment