Wiktor123

kolumna z maksymalna suma

Jul 15th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. {
  2. class Program
  3. {
  4. static double KtoraKolumna(int[,] a)
  5. {
  6. double[] srednia = new double[5];
  7.  
  8. for (int i = 0; i < 5; i++)
  9. {
  10. srednia[i] = 0;
  11. for (int j = 0; j < 4; j++)
  12. {
  13. srednia[i] += a[i, j];
  14. }
  15.  
  16. srednia[i] /= 4;
  17. }
  18. int nrKolumny = Array.IndexOf(srednia, srednia.Max());
  19.  
  20. return nrKolumny;
  21. }
  22. static void Main(string[] args)
  23. {
  24. int[,] a = new int[5, 4] { { 1, 1, 1, 0 }, { -2, -3, 2, 1 }, { 2, -5, 0, -1 }, { -3, 4, 6, 2 }, { -6, 6, 3, 4 } };
  25.  
  26. Console.WriteLine("numer kolumny z maksymalnÄ… sumÄ… = " + KtoraKolumna(a));
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment