NedyalkoKikov

ArraySumMaxFirstLast

May 26th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 ArraySumMaxFirstLast
  8. {
  9. class ArraySumMaxFirstLast
  10. {
  11. static void Main()
  12. {
  13. int[] Arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. int sum = 0;
  15. int min = Arr[0];
  16. int max = Arr[0];
  17. for (int i = 0; i < Arr.Length; i++)
  18. {
  19. sum += Arr[i];
  20. if(Arr[i] < min)
  21. {
  22. min = Arr[i];
  23. }
  24. if(Arr[i] > max)
  25. {
  26. max = Arr[i];
  27. }
  28. }
  29. Console.WriteLine("sum - {0}",sum);
  30. Console.WriteLine("min - {0}",min);
  31. Console.WriteLine("max - {0}",max);
  32. Console.WriteLine("firts - {0}",Arr[0]);
  33. Console.WriteLine("last - {0}",Arr[Arr.Length-1]);
  34. Console.WriteLine("average - {0}", (double)sum / Arr.Length);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment