Blagovest

SumMinMaxFirstLastAverage

Jul 27th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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 loops
  8. {
  9. class loops
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. int[] arr = new int[n];
  15. for (int i = 0; i < n; i++)
  16. {
  17. arr[i] = int.Parse(Console.ReadLine());
  18. }
  19. int sum = 0;
  20. int min = int.MaxValue;
  21. int max = int.MinValue;
  22.  
  23. for (int i = 0; i < arr.Length; i++)
  24. {
  25. sum = sum+arr[i];
  26. if (arr[i]<min)
  27. {
  28. min = arr[i];
  29. }
  30. if (max<arr[i])
  31. {
  32. max = arr[i];
  33. }
  34. }
  35. Console.WriteLine("sum = "+ sum);
  36. Console.WriteLine("min = "+ min);
  37. Console.WriteLine("max = "+ max);
  38. Console.WriteLine("first = "+ arr[0]);
  39. Console.WriteLine("last = "+ arr[arr.Length-1]);
  40. Console.WriteLine("Average = "+(double) sum/n);
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment