desislava_topuzakova

Сума и средноаритметично

Jun 6th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Demo
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<int> list = new List<int> { 3, 4, 5, 6 };
  11. Console.WriteLine(Sum(list));
  12. Console.WriteLine(Average(list));
  13.  
  14.  
  15.  
  16.  
  17.  
  18. }
  19.  
  20. public static int Sum( List<int> list)
  21. {
  22. int sum = 0;
  23. foreach(int number in list)
  24. {
  25. sum += number;
  26. }
  27.  
  28. return sum;
  29.  
  30. }
  31.  
  32.  
  33. public static double Average(List<int> list)
  34. {
  35. return Sum(list) * 1.0 / list.Count;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment