Advertisement
Wiktor123

średnia ar

Jul 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8. public class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. //Your code goes here
  13.  
  14. double[,] tablica = {
  15. {1 ,2 ,3},
  16. {4 ,5 ,6},
  17. {7, 8, 1}
  18. };
  19.  
  20. Console.WriteLine("Najnizsza srednia: {0}", Average(tablica));
  21. }
  22.  
  23. public static double Average(double[,] tablica)
  24. {
  25. int liczbaWierszy = tablica.GetLength(0);
  26. int liczbaKolumn = tablica.GetLength(1);
  27.  
  28. double[] sumaKolumn = new double[liczbaKolumn];
  29. for (int w = 0; w < liczbaWierszy; w++)
  30. {
  31. for (int k = 0; k < liczbaKolumn; k++)
  32. {
  33. sumaKolumn[k] += tablica[w, k];
  34. }
  35. }
  36. for (int i = 0; i < liczbaKolumn; i++)
  37. {
  38. sumaKolumn[i] = sumaKolumn[i] / liczbaWierszy;
  39. }
  40. return sumaKolumn.Min();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement