Guest User

Untitled

a guest
Feb 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace cazzo
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             const int DIMENSIONI_MAT = 4;
  13.             int[,] matrice = new int[DIMENSIONI_MAT, DIMENSIONI_MAT];
  14.             caricaMatrice(matrice,0,11);
  15.             stampaMatrice(matrice);
  16.             int risultato = sommaMat(matrice);
  17.             Console.WriteLine(risultato);
  18.         }
  19.  
  20.         private static int sommaMat(int[,] matrice)
  21.         {
  22.             int sommaSup, sommaInf;
  23.             sommaSup = sommaInf = 0;
  24.             for (int i = 0; i < matrice.GetLength(0); i++)
  25.             {
  26.                 for (int j = matrice.GetLength(1) - i - 2; j >= 0; j--)
  27.                     sommaSup += matrice[i, j];
  28.                 for (int j = matrice.GetLength(1) - 1; j > matrice.GetLength(1) - i - 1; j--)
  29.                     sommaInf += matrice[i, j];
  30.             }
  31.             Console.WriteLine("Sup:{0} - Inf: {1}",sommaSup, sommaInf);
  32.             return sommaSup > sommaInf ? -1 : 1;
  33.         }
  34.  
  35.         private static void caricaMatrice(int[,] matrice,int min,int max)
  36.         {
  37.             Random caso = new Random();
  38.             for (int i = 0; i < matrice.GetLength(0); i++)
  39.                 for (int j = 0; j < matrice.GetLength(1); j++)
  40.                     matrice[i, j] = caso.Next(min, max + 1);
  41.         }
  42.  
  43.  
  44.         private static void stampaMatrice(int[,] matrice)
  45.         {
  46.             for (int i = 0; i < matrice.GetLength(0); i++)
  47.             {
  48.                 for (int j = 0; j < matrice.GetLength(1); j++)
  49.                 {
  50.                     Console.Write("{0,3}", matrice[i, j]);
  51.                 }
  52.                 Console.WriteLine();
  53.             }
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment