Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _01._Array_Statistics
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine(); //"2 3 4 5 6 1".Split(' ') -> ["2", "3", "4", "5", "6", "1"]
- int[] numbers = input //"2 3 4 5 6 1"
- .Split(' ') //["2", "3", "4", "5", "6", "1"]
- .Select(int.Parse) // "2" -> 2, "3" -> 3, "4" -> 4, "5" -> 5, "6" -> 6, "1" -> 1
- .ToArray(); //[2, 3, 4, 5, 6, 1]
- //всички елементи
- int sum = 0;
- int min = int.MaxValue;
- int max = int.MinValue;
- for (int index = 0; index <= numbers.Length - 1; index++)
- {
- int currentElement = numbers[index];
- sum = sum + currentElement; //сумираме числата
- //проверка за минимум
- if (currentElement < min)
- {
- min = currentElement;
- }
- //проверка за максимум
- if (currentElement > max)
- {
- max = currentElement;
- }
- }
- Console.WriteLine("Min = " + min);
- Console.WriteLine("Max = " + max);
- Console.WriteLine("Sum = " + sum);
- double average = sum * 1.0 / numbers.Length;
- Console.WriteLine("Average = " + average);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment