Advertisement
vencinachev

MinMaxSumAvg

Mar 13th, 2022
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 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 Lists
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] numbers = Console.ReadLine()
  14.                             .Split(' ')
  15.                             .Select(el => int.Parse(el))
  16.                             .ToArray();
  17.  
  18.             int min = numbers[0];
  19.             int max = numbers[0];
  20.             int sum = 0;
  21.             foreach (int item in numbers)
  22.             {
  23.                 sum += item;
  24.                 if (item < min)
  25.                 {
  26.                     min = item;
  27.                 }
  28.                 if (item > max)
  29.                 {
  30.                     max = item;
  31.                 }
  32.             }
  33.             double avg = (double)sum / numbers.Length;
  34.             Console.WriteLine($"Min = {min}");
  35.             Console.WriteLine($"Max = {max}");
  36.             Console.WriteLine($"Sum = {sum}");
  37.             Console.WriteLine($"Average = {avg:F1}");
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement