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;
- namespace cazzo
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int DIMENSIONI_MAT = 4;
- int[,] matrice = new int[DIMENSIONI_MAT, DIMENSIONI_MAT];
- caricaMatrice(matrice,0,11);
- stampaMatrice(matrice);
- int risultato = sommaMat(matrice);
- Console.WriteLine(risultato);
- }
- private static int sommaMat(int[,] matrice)
- {
- int sommaSup, sommaInf;
- sommaSup = sommaInf = 0;
- for (int i = 0; i < matrice.GetLength(0); i++)
- {
- for (int j = matrice.GetLength(1) - i - 2; j >= 0; j--)
- sommaSup += matrice[i, j];
- for (int j = matrice.GetLength(1) - 1; j > matrice.GetLength(1) - i - 1; j--)
- sommaInf += matrice[i, j];
- }
- Console.WriteLine("Sup:{0} - Inf: {1}",sommaSup, sommaInf);
- return sommaSup > sommaInf ? -1 : 1;
- }
- private static void caricaMatrice(int[,] matrice,int min,int max)
- {
- Random caso = new Random();
- for (int i = 0; i < matrice.GetLength(0); i++)
- for (int j = 0; j < matrice.GetLength(1); j++)
- matrice[i, j] = caso.Next(min, max + 1);
- }
- private static void stampaMatrice(int[,] matrice)
- {
- for (int i = 0; i < matrice.GetLength(0); i++)
- {
- for (int j = 0; j < matrice.GetLength(1); j++)
- {
- Console.Write("{0,3}", matrice[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment