Copiato 6 funzioni dall'esercizio precedente
This commit is contained in:
parent
282e5ed657
commit
9441f22322
174
Program.cs
174
Program.cs
@ -1,9 +1,173 @@
|
|||||||
namespace matrix_2;
|
namespace matrix_2;
|
||||||
|
|
||||||
class Program
|
class Program {
|
||||||
{
|
static void Main(string[] args) {
|
||||||
static void Main(string[] args)
|
Menu();
|
||||||
{
|
}
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
|
static void Menu() {
|
||||||
|
Console.Clear();
|
||||||
|
int scelta;
|
||||||
|
int[,] matrix = null;
|
||||||
|
int[] array = null;
|
||||||
|
do {
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Inserire un'opzione:");
|
||||||
|
Console.WriteLine("1. Crea matrice");
|
||||||
|
Console.WriteLine("2. Stampa matrice");
|
||||||
|
Console.WriteLine("3. Somma diagonale principale");
|
||||||
|
Console.WriteLine("4. Media diagonale principale");
|
||||||
|
Console.WriteLine("5. Prodotto diagonale principale");
|
||||||
|
Console.WriteLine("6. Valore minimo e massimo diagonale principale");
|
||||||
|
Console.WriteLine("0. Esci");
|
||||||
|
Console.Write("Scelta: ");
|
||||||
|
scelta = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
switch (scelta) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Console.Clear();
|
||||||
|
matrix = CreaMatrice();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
MostraMatrice(matrix);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di mostrarla.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
Console.WriteLine($"La somma degli elementi della diagonale principale è {SommaMatriceDiagonale(matrix)}");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di calcolare la somma della diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
Console.WriteLine($"La media degli elementi della diagonale principale è {SommaMatriceDiagonale(matrix) / matrix.GetLength(0)}");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di calcolare la media della diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
Console.WriteLine($"Il prodotto degli elementi della diagonale principale è {ProdottoMatriceDiagonale(matrix)}");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di calcolare il prodotto della diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
Console.Clear();
|
||||||
|
if (matrix != null) {
|
||||||
|
array = MinimoMassimoMatriceDiagonale(matrix, 0);
|
||||||
|
Console.WriteLine($"Il valore minimo è {array[0]} e si trova in posizione {array[1]},{array[2]}");
|
||||||
|
array = MinimoMassimoMatriceDiagonale(matrix, 1);
|
||||||
|
Console.WriteLine($"Il valore massimo è {array[0]} e si trova in posizione {array[1]},{array[2]}");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("È necessario creare la matrice prima di calcolare il minimo e il massimo della diagonale principale.");
|
||||||
|
}
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Opzione non valida.");
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (scelta != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Pausa() {
|
||||||
|
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||||
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[,] CreaMatrice() {
|
||||||
|
int dimensione = 0;
|
||||||
|
Console.Write("Inserire le dimensioni della matrice: ");
|
||||||
|
dimensione = Convert.ToInt32(Console.ReadLine());
|
||||||
|
int[,] ritorno = new int[dimensione, dimensione];
|
||||||
|
RiempiMatrice(ritorno);
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
static void MostraMatrice(int[,] p_matrice) {
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
||||||
|
Console.Write(p_matrice[r, c] + " ");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void RiempiMatrice(int[,] p_matrice) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
for (int c = 0; c < p_matrice.GetLength(1); c++) {
|
||||||
|
p_matrice[r, c] = rnd.Next(6); //TODO: rimettere il valore a 101
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SommaMatriceDiagonale(int[,] p_matrice) {
|
||||||
|
int ritorno = 0;
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
ritorno = ritorno + p_matrice[r, r];
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ProdottoMatriceDiagonale(int[,] p_matrice) {
|
||||||
|
int ritorno = 1;
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
ritorno = ritorno * p_matrice[r, r];
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[] MinimoMassimoMatriceDiagonale(int[,] p_matrice, int p_scelta) {
|
||||||
|
int[] ritorno = new int[3];
|
||||||
|
switch (p_scelta) {
|
||||||
|
case 0:
|
||||||
|
ritorno[0] = Int32.MaxValue;
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
if (p_matrice[r, r] < ritorno[0]) {
|
||||||
|
ritorno[0] = p_matrice[r, r];
|
||||||
|
ritorno[1] = r;
|
||||||
|
ritorno[2] = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ritorno[0] = Int32.MinValue;
|
||||||
|
for (int r = 0; r < p_matrice.GetLength(0); r++) {
|
||||||
|
if (p_matrice[r, r] > ritorno[0]) {
|
||||||
|
ritorno[0] = p_matrice[r, r];
|
||||||
|
ritorno[1] = r;
|
||||||
|
ritorno[2] = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
bin/Debug/net9.0/matrix_2
Executable file
BIN
bin/Debug/net9.0/matrix_2
Executable file
Binary file not shown.
23
bin/Debug/net9.0/matrix_2.deps.json
Normal file
23
bin/Debug/net9.0/matrix_2.deps.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"runtimeTarget": {
|
||||||
|
"name": ".NETCoreApp,Version=v9.0",
|
||||||
|
"signature": ""
|
||||||
|
},
|
||||||
|
"compilationOptions": {},
|
||||||
|
"targets": {
|
||||||
|
".NETCoreApp,Version=v9.0": {
|
||||||
|
"matrix_2/1.0.0": {
|
||||||
|
"runtime": {
|
||||||
|
"matrix_2.dll": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"libraries": {
|
||||||
|
"matrix_2/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"serviceable": false,
|
||||||
|
"sha512": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
bin/Debug/net9.0/matrix_2.dll
Normal file
BIN
bin/Debug/net9.0/matrix_2.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net9.0/matrix_2.pdb
Normal file
BIN
bin/Debug/net9.0/matrix_2.pdb
Normal file
Binary file not shown.
12
bin/Debug/net9.0/matrix_2.runtimeconfig.json
Normal file
12
bin/Debug/net9.0/matrix_2.runtimeconfig.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"runtimeOptions": {
|
||||||
|
"tfm": "net9.0",
|
||||||
|
"framework": {
|
||||||
|
"name": "Microsoft.NETCore.App",
|
||||||
|
"version": "9.0.0"
|
||||||
|
},
|
||||||
|
"configProperties": {
|
||||||
|
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
// <autogenerated />
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
|
||||||
BIN
obj/Debug/net9.0/apphost
Executable file
BIN
obj/Debug/net9.0/apphost
Executable file
Binary file not shown.
22
obj/Debug/net9.0/matrix_2.AssemblyInfo.cs
Normal file
22
obj/Debug/net9.0/matrix_2.AssemblyInfo.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
[assembly: System.Reflection.AssemblyCompanyAttribute("matrix_2")]
|
||||||
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+282e5ed6576673e17566281d70cd78d712d58a3a")]
|
||||||
|
[assembly: System.Reflection.AssemblyProductAttribute("matrix_2")]
|
||||||
|
[assembly: System.Reflection.AssemblyTitleAttribute("matrix_2")]
|
||||||
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
||||||
|
// Generated by the MSBuild WriteCodeFragment class.
|
||||||
|
|
||||||
1
obj/Debug/net9.0/matrix_2.AssemblyInfoInputs.cache
Normal file
1
obj/Debug/net9.0/matrix_2.AssemblyInfoInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
5c574530e7a1f84a8ba8807f4f033310b4dab2123c9302f06e61373058a1456f
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
is_global = true
|
||||||
|
build_property.TargetFramework = net9.0
|
||||||
|
build_property.TargetPlatformMinVersion =
|
||||||
|
build_property.UsingMicrosoftNETSdkWeb =
|
||||||
|
build_property.ProjectTypeGuids =
|
||||||
|
build_property.InvariantGlobalization =
|
||||||
|
build_property.PlatformNeutralAssembly =
|
||||||
|
build_property.EnforceExtendedAnalyzerRules =
|
||||||
|
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||||
|
build_property.RootNamespace = matrix_2
|
||||||
|
build_property.ProjectDir = /home/Verde/git/matrix_2/
|
||||||
|
build_property.EnableComHosting =
|
||||||
|
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||||
|
build_property.EffectiveAnalysisLevelStyle = 9.0
|
||||||
|
build_property.EnableCodeStyleSeverity =
|
||||||
8
obj/Debug/net9.0/matrix_2.GlobalUsings.g.cs
Normal file
8
obj/Debug/net9.0/matrix_2.GlobalUsings.g.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// <auto-generated/>
|
||||||
|
global using global::System;
|
||||||
|
global using global::System.Collections.Generic;
|
||||||
|
global using global::System.IO;
|
||||||
|
global using global::System.Linq;
|
||||||
|
global using global::System.Net.Http;
|
||||||
|
global using global::System.Threading;
|
||||||
|
global using global::System.Threading.Tasks;
|
||||||
BIN
obj/Debug/net9.0/matrix_2.assets.cache
Normal file
BIN
obj/Debug/net9.0/matrix_2.assets.cache
Normal file
Binary file not shown.
1
obj/Debug/net9.0/matrix_2.csproj.CoreCompileInputs.cache
Normal file
1
obj/Debug/net9.0/matrix_2.csproj.CoreCompileInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
d7cdf28c1642372f088ecc914eae6fc301b23d42834d9d70ec74a1e394f57371
|
||||||
14
obj/Debug/net9.0/matrix_2.csproj.FileListAbsolute.txt
Normal file
14
obj/Debug/net9.0/matrix_2.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/home/Verde/git/matrix_2/bin/Debug/net9.0/matrix_2
|
||||||
|
/home/Verde/git/matrix_2/bin/Debug/net9.0/matrix_2.deps.json
|
||||||
|
/home/Verde/git/matrix_2/bin/Debug/net9.0/matrix_2.runtimeconfig.json
|
||||||
|
/home/Verde/git/matrix_2/bin/Debug/net9.0/matrix_2.dll
|
||||||
|
/home/Verde/git/matrix_2/bin/Debug/net9.0/matrix_2.pdb
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.GeneratedMSBuildEditorConfig.editorconfig
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.AssemblyInfoInputs.cache
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.AssemblyInfo.cs
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.csproj.CoreCompileInputs.cache
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.dll
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/refint/matrix_2.dll
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.pdb
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/matrix_2.genruntimeconfig.cache
|
||||||
|
/home/Verde/git/matrix_2/obj/Debug/net9.0/ref/matrix_2.dll
|
||||||
BIN
obj/Debug/net9.0/matrix_2.dll
Normal file
BIN
obj/Debug/net9.0/matrix_2.dll
Normal file
Binary file not shown.
1
obj/Debug/net9.0/matrix_2.genruntimeconfig.cache
Normal file
1
obj/Debug/net9.0/matrix_2.genruntimeconfig.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
d511960b683ae296ad19e3d228eaa99d7fba6ac75fc39a13286e5938c333fe4f
|
||||||
BIN
obj/Debug/net9.0/matrix_2.pdb
Normal file
BIN
obj/Debug/net9.0/matrix_2.pdb
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/ref/matrix_2.dll
Normal file
BIN
obj/Debug/net9.0/ref/matrix_2.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/refint/matrix_2.dll
Normal file
BIN
obj/Debug/net9.0/refint/matrix_2.dll
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user