desislava_topuzakova

Untitled

Feb 21st, 2021
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Arrays
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = Console.ReadLine();
  11. int[] numbers = input.Split(" ").Select(int.Parse).ToArray();
  12. //"2 3 4 5 6 1" -> ["2", "3", "4", "5", "6", "1"] ->
  13. //-> [2,3,4,5,6,1]
  14. int sum = 0;
  15. int min = int.MaxValue; //256575....
  16. int max = int.MinValue; //-223423423....
  17. for (int index = 0; index <= numbers.Length - 1; index++)
  18. {
  19. int currentNumber = numbers[index];
  20. sum += currentNumber;
  21.  
  22. if(currentNumber < min)
  23. {
  24. min = currentNumber;
  25. }
  26.  
  27. if(currentNumber > max)
  28. {
  29. max = currentNumber;
  30. }
  31.  
  32.  
  33. }
  34.  
  35. Console.WriteLine("Sum = " + sum);
  36. double average = sum * 1.0 / numbers.Length;
  37. Console.WriteLine("Average = " + average);
  38. Console.WriteLine("Min = " + min);
  39. Console.WriteLine("Max = " + max);
  40.  
  41. }
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment