Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Algorithms06
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = 5, k = 5;
- int[] sumA = new int[n];
- int[] sumB = new int[k];
- int[] sumC = new int[2];
- int[,] tab = new int[n, k];
- Random rnd = new Random();
- for(int i=0; i<tab.GetLength(0); i++)
- {
- for(int j=0; j<tab.GetLength(1); j++)
- {
- tab[i, j] = rnd.Next(2);
- Console.Write("{0} ", tab[i, j]);
- }
- Console.WriteLine();
- }
- for (int i = 0; i < tab.GetLength(0); i++)
- {
- for (int j = 0; j < tab.GetLength(1); j++)
- {
- sumA[i] += tab[i, j];
- sumB[j] += tab[i, j];
- }
- if(n==k)
- {
- sumC[0] += tab[i, i];
- sumC[1] += tab[tab.GetLength(0) - (i + 1), i];
- }
- }
- int max=0;
- string maxString="";
- for(int i=0; i<n; i++)
- {
- if (sumA[i] > max)
- {
- max = sumA[i];
- maxString = "x" + (i+1);
- if (sumB[i] > max)
- {
- max = sumB[i];
- maxString = "y" + (i+1);
- }
- }
- }
- if(n==k)
- {
- for (int i = 0; i < 2; i++)
- {
- if (sumC[i] > max)
- {
- max = sumC[i];
- maxString = "z" + (i + 1);
- }
- }
- }
- Console.WriteLine($"Wynik: {maxString} = {max}");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement