Opzione 5 & 6
This commit is contained in:
parent
b00a9cea81
commit
539f1a7b8c
148
Program.cs
148
Program.cs
@ -8,7 +8,7 @@ class Program {
|
|||||||
static void Menu() {
|
static void Menu() {
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
int scelta;
|
int scelta;
|
||||||
int[,] matrix = null;
|
int[,] matrix1 = null, matrix2 = null;
|
||||||
int[] array = null;
|
int[] array = null;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@ -18,9 +18,9 @@ class Program {
|
|||||||
Console.WriteLine("2. Somma diagonale secondaria");
|
Console.WriteLine("2. Somma diagonale secondaria");
|
||||||
Console.WriteLine("3. Media diagonale secondaria");
|
Console.WriteLine("3. Media diagonale secondaria");
|
||||||
Console.WriteLine("4. Prodotto diagonale secondaria");
|
Console.WriteLine("4. Prodotto diagonale secondaria");
|
||||||
Console.WriteLine("6. Valore minimo e massimo diagonale principale");
|
Console.WriteLine("5. Valore minimo e massimo diagonale secondaria");
|
||||||
Console.WriteLine("7. Trova zeri sulla diagonale principale");
|
Console.WriteLine("6. Somma 2 matrici");
|
||||||
Console.WriteLine("8. Cerca sulla diagonale principale");
|
Console.WriteLine("7. MOstra matrice trasposta");
|
||||||
Console.WriteLine("0. Esci");
|
Console.WriteLine("0. Esci");
|
||||||
Console.Write("Scelta: ");
|
Console.Write("Scelta: ");
|
||||||
scelta = Convert.ToInt32(Console.ReadLine());
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
@ -30,16 +30,16 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
matrix = CreaMatrice();
|
matrix1 = CreaMatriceQuadrata();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("La matrice creata è la seguente:");
|
Console.WriteLine("La matrice creata è la seguente:");
|
||||||
MostraMatrice(matrix);
|
MostraMatrice(matrix1);
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
Console.WriteLine($"La somma degli elementi della diagonale principale è {SommaMatriceDiagonale2(matrix)}");
|
Console.WriteLine($"La somma degli elementi della diagonale principale è {SommaMatriceDiagonale2(matrix1)}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console.WriteLine("È necessario creare la matrice prima di calcolare la somma della diagonale principale.");
|
Console.WriteLine("È necessario creare la matrice prima di calcolare la somma della diagonale principale.");
|
||||||
@ -48,8 +48,8 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
Console.WriteLine($"La media degli elementi della diagonale principale è {SommaMatriceDiagonale2(matrix) / matrix.GetLength(0)}");
|
Console.WriteLine($"La media degli elementi della diagonale principale è {SommaMatriceDiagonale2(matrix1) / matrix1.GetLength(0)}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console.WriteLine("È necessario creare la matrice prima di calcolare la media della diagonale principale.");
|
Console.WriteLine("È necessario creare la matrice prima di calcolare la media della diagonale principale.");
|
||||||
@ -58,8 +58,8 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
Console.WriteLine($"Il prodotto degli elementi della diagonale principale è {ProdottoMatriceDiagonale2(matrix)}");
|
Console.WriteLine($"Il prodotto degli elementi della diagonale principale è {ProdottoMatriceDiagonale2(matrix1)}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console.WriteLine("È necessario creare la matrice prima di calcolare il prodotto della diagonale principale.");
|
Console.WriteLine("È necessario creare la matrice prima di calcolare il prodotto della diagonale principale.");
|
||||||
@ -68,8 +68,9 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
//Console.WriteLine($"Il prodotto degli elementi della diagonale principale è {ProdottoMatriceDiagonale(matrix)}");
|
MostraMinimoMassimoMatrice(MinimoMassimoMatriceDiagonale2(matrix1, 0), 0);
|
||||||
|
MostraMinimoMassimoMatrice(MinimoMassimoMatriceDiagonale2(matrix1, 1), 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console.WriteLine("È necessario creare la matrice prima di calcolare il prodotto della diagonale principale.");
|
Console.WriteLine("È necessario creare la matrice prima di calcolare il prodotto della diagonale principale.");
|
||||||
@ -78,20 +79,19 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
matrix1 = CreaMatrice();
|
||||||
//array = MinimoMassimoMatriceDiagonale(matrix, 0);
|
matrix2 = CreaMatrice();
|
||||||
Console.WriteLine($"Il valore minimo è {array[0]} e si trova in posizione {array[1]},{array[2]}");
|
if (matrix1.GetLength(0) != matrix2.GetLength(0) && matrix1.GetLength(1) != matrix2.GetLength(1)) {
|
||||||
//array = MinimoMassimoMatriceDiagonale(matrix, 1);
|
Console.WriteLine("Per effettuare la somma tra due matrici, queste devono essere delle stesse dimensioni.");
|
||||||
Console.WriteLine($"Il valore massimo è {array[0]} e si trova in posizione {array[1]},{array[2]}");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Console.WriteLine("È necessario creare la matrice prima di calcolare il minimo e il massimo della diagonale principale.");
|
MostraMatrice(SommaMatrici(matrix1, matrix2));
|
||||||
}
|
}
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
if (true) {
|
if (true) {
|
||||||
Console.WriteLine("Sulla diagonale principale sono presenti degli zeri");
|
Console.WriteLine("Sulla diagonale principale sono presenti degli zeri");
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ class Program {
|
|||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
if (matrix != null) {
|
if (matrix1 != null) {
|
||||||
Console.Write("Inserire un numero da cercare: ");
|
Console.Write("Inserire un numero da cercare: ");
|
||||||
if (true) {
|
if (true) {
|
||||||
Console.WriteLine("Elemento trovato");
|
Console.WriteLine("Elemento trovato");
|
||||||
@ -135,7 +135,7 @@ class Program {
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int[,] CreaMatrice() {
|
static int[,] CreaMatriceQuadrata() {
|
||||||
int dimensione = 0;
|
int dimensione = 0;
|
||||||
Console.Write("Inserire la dimensione della matrice: ");
|
Console.Write("Inserire la dimensione della matrice: ");
|
||||||
dimensione = Convert.ToInt32(Console.ReadLine());
|
dimensione = Convert.ToInt32(Console.ReadLine());
|
||||||
@ -172,4 +172,106 @@ class Program {
|
|||||||
}
|
}
|
||||||
return ritorno;
|
return ritorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int[,] MinimoMassimoMatriceDiagonale2(int[,] p_matrice, int p_scelta) {
|
||||||
|
int[,] ritorno = null;
|
||||||
|
switch (p_scelta) {
|
||||||
|
case 0:
|
||||||
|
int min = int.MaxValue;
|
||||||
|
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
if (p_matrice[r, p_matrice.GetLength(1) - 1 - r] < min) {
|
||||||
|
min = p_matrice[r, p_matrice.GetLength(1) - 1 - r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ritorno = TrovaMatrice(p_matrice, min);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
int max = int.MinValue;
|
||||||
|
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
if (p_matrice[r, p_matrice.GetLength(1) - 1 - r] > max) {
|
||||||
|
max = p_matrice[r, p_matrice.GetLength(1) - 1 - r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ritorno = TrovaMatrice(p_matrice, max);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[,] TrovaMatrice(int[,] p_matrice, int p_DaTrovare) {
|
||||||
|
int[,] ritorno = new int[p_matrice.GetLength(0), p_matrice.GetLength(1)];
|
||||||
|
RiempiMatriceMax(ritorno);
|
||||||
|
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
if (p_matrice[r, p_matrice.GetLength(1) - 1 - r] == p_DaTrovare) {
|
||||||
|
ritorno[r, p_matrice.GetLength(1) - 1 - r] = p_DaTrovare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RiempiMatriceMax(int[,] p_matrice) {
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
||||||
|
p_matrice[r, c] = int.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void MostraMinimoMassimoMatrice(int[,] p_matrice, int p_scelta) {
|
||||||
|
bool trovato = false;
|
||||||
|
string stringa = "";
|
||||||
|
|
||||||
|
switch (p_scelta) {
|
||||||
|
case 0:
|
||||||
|
stringa = "minimo";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
stringa = "massimo";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
||||||
|
if (p_matrice[r, c] != int.MaxValue) {
|
||||||
|
if (!trovato) {
|
||||||
|
Console.WriteLine($"Il valore {stringa} è {p_matrice[r, c]} e si trova nelle posizioni:");
|
||||||
|
trovato = true;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"{r}, {c}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[,] CreaMatrice() {
|
||||||
|
int righe, colonne;
|
||||||
|
Console.Write("Inserire il numero di righe della matrice: ");
|
||||||
|
righe = Convert.ToInt32(Console.ReadLine());
|
||||||
|
Console.Write("Inserire il numero di colonne della matrice: ");
|
||||||
|
colonne = Convert.ToInt32(Console.ReadLine());
|
||||||
|
int[,] ritorno = new int[righe, colonne];
|
||||||
|
for (int r = 0; r < ritorno.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < ritorno.GetLength(1); c++) {
|
||||||
|
Console.Write($"Inserire l'elemento in posizione {r}, {c}: ");
|
||||||
|
ritorno[r, c] = Convert.ToInt32(Console.ReadLine());
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[,] SommaMatrici(int[,] p_matrice1, int[,] p_matrice2) {
|
||||||
|
int[,] ritorno = new int[p_matrice1.GetLength(0), p_matrice1.GetLength(1)];
|
||||||
|
for (int r = 0; r < p_matrice1.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < p_matrice1.GetLength(1); c++) {
|
||||||
|
ritorno[r, c] = p_matrice1[r, c] + p_matrice2[r, c];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_3")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_3")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6014c313b202cd6198ffad5fdc9677bf63ff7c11")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b00a9cea811f930eff832555c7d39711548491f2")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("matrix_3")]
|
[assembly: System.Reflection.AssemblyProductAttribute("matrix_3")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_3")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_3")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
c406b3a08bd253a1bcf5b3ae92da91aa3d5278f12f55945bc57b8ccec301f14d
|
24011d8278f0ee5fff0d76f8ca60ae6d36888403cf7bf503a41a322503a8e8e7
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user