Aggiunte le opzioni 7 e 8
This commit is contained in:
parent
9441f22322
commit
396db8dcbf
49
Program.cs
49
Program.cs
@ -1,4 +1,6 @@
|
|||||||
namespace matrix_2;
|
using System.Reflection.Metadata;
|
||||||
|
|
||||||
|
namespace matrix_2;
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
@ -20,6 +22,8 @@ class Program {
|
|||||||
Console.WriteLine("4. Media diagonale principale");
|
Console.WriteLine("4. Media diagonale principale");
|
||||||
Console.WriteLine("5. Prodotto diagonale principale");
|
Console.WriteLine("5. Prodotto diagonale principale");
|
||||||
Console.WriteLine("6. Valore minimo e massimo diagonale principale");
|
Console.WriteLine("6. Valore minimo e massimo diagonale principale");
|
||||||
|
Console.WriteLine("7. Trova zeri sulla diagonale principale");
|
||||||
|
Console.WriteLine("8. Cerca sulla diagonale principale");
|
||||||
Console.WriteLine("0. Esci");
|
Console.WriteLine("0. Esci");
|
||||||
Console.Write("Scelta: ");
|
Console.Write("Scelta: ");
|
||||||
scelta = Convert.ToInt32(Console.ReadLine());
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
@ -85,6 +89,37 @@ class Program {
|
|||||||
}
|
}
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
if (TrovaDiagonale(matrix, 0)) {
|
||||||
|
Console.WriteLine("Sulla diagonale principale sono presenti degli zeri");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Sulla diagonale principale non sono presenti degli zeri");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di cercare gli zeri sulla diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
Console.Write("Inserire un numero da cercare: ");
|
||||||
|
if (TrovaDiagonale(matrix, Convert.ToInt32(Console.ReadLine()))) {
|
||||||
|
Console.WriteLine("Elemento trovato");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Elemento non trovato");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di cercare un elemento sulla diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Opzione non valida.");
|
Console.WriteLine("Opzione non valida.");
|
||||||
Pausa();
|
Pausa();
|
||||||
@ -120,7 +155,7 @@ class Program {
|
|||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
||||||
p_matrice[r, c] = rnd.Next(6); //TODO: rimettere il valore a 101
|
p_matrice[r, c] = rnd.Next(101);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,4 +205,14 @@ class Program {
|
|||||||
|
|
||||||
return ritorno;
|
return ritorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool TrovaDiagonale(int[,] p_matrice, int p_DaTrovare) {
|
||||||
|
bool ritorno = false;
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0) && !ritorno; r++) {
|
||||||
|
if (p_matrice[r, r] == p_DaTrovare) {
|
||||||
|
ritorno = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -13,10 +13,10 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_2")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_2")]
|
||||||
[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+282e5ed6576673e17566281d70cd78d712d58a3a")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9441f2232224090ad4976d49bcfdbeb7d01779f6")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("matrix_2")]
|
[assembly: System.Reflection.AssemblyProductAttribute("matrix_2")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_2")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_2")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
||||||
// Generated by the MSBuild WriteCodeFragment class.
|
// Generato dalla classe WriteCodeFragment di MSBuild.
|
||||||
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
5c574530e7a1f84a8ba8807f4f033310b4dab2123c9302f06e61373058a1456f
|
0e56d238097473adb0a30716e289d969291c614c61b91e302df23fb47e627318
|
||||||
|
|||||||
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