Rimossa StampaArray e completata la logica

This commit is contained in:
La Programmatrice Verde 2025-02-07 09:43:19 +01:00
parent 39331d79c2
commit 375e8e3138
16 changed files with 104 additions and 23 deletions

View File

@ -2,30 +2,21 @@
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello, World!");
ContaOccorrenze(Input());
}
static int[] Input() {
//dichiarazione e inizializzazione variabili
int dimensione, input = 0, i = 0;
//input della dimensione
do {
Console.Write("Quanti valori vuoi inserire? ");
dimensione = Convert.ToInt32(Console.ReadLine());
if (dimensione <= 0) {
Console.WriteLine("Dimensione non valida.");
Pausa();
}
}
while (dimensione <= 0);
Console.Clear();
//creazione array
//dichiarazione e inizializzazione variabili
int input = 0, i = 0;
const int dimensione = 10;
int[] ritorno = new int[dimensione];
//Riempimento array
while (i < dimensione || input == Int32.MaxValue) {
Console.Write($"Inserire il valore n. {i}: ");
Console.Write($"Inserire il valore n. {i + 1}: ");
input = Convert.ToInt32(Console.ReadLine());
if (input == Int32.MaxValue) {
if (input == Int32.MaxValue) {//escludo un valore per effettuare la stampa correttamente successivamente
Console.Write("Valore non valido");
Pausa();
}
@ -38,12 +29,51 @@ class Program {
return ritorno;
}
static void ContaOccorrenze(int[] p_array) {
Console.Clear();
static void StampaArray(int[] p_array) {
for (int i = 0; i < p_array.Length; i++) {
Console.WriteLine($"Elemento {i}: {p_array[i]}");
//dichiarazione e inizializzazione variabili
int[] elementi = new int[p_array.Length];
int[] occorrenze = new int[p_array.Length];
int temp = Int32.MaxValue, occorrenza;
bool incontrato = false;
for (int i = 0; i < p_array.Length; i++) {//riempio gli array con un valore non inseribile per poi effettuare la stampa
elementi[i] = Int32.MaxValue;
occorrenze[i] = Int32.MaxValue;
}
for (int i = 0; i < p_array.Length; i++) {
occorrenza = 0;//reset del contatore delle occorrenze
if (p_array[i] != temp) {
temp = p_array[i];
for (int j = 0; j < p_array.Length; j++) { //verifico se p_array[i] è già nell'array elementi
if (elementi[j] == temp) {
incontrato = true;
}
}
if (!incontrato) {//se p_array[i] non è nell'array elementi
for (int j = 0; j < p_array.Length; j++) {
if (p_array[j] == temp) {
occorrenza++;//conto tutte le volte che si ripete
}
}
elementi[i] = temp;//segno l'elemento corrente
occorrenze[i] = occorrenza;//segno quante volte occorre
}
incontrato = false;//reset della variabile
}
}
//mostro i risultati
for (int i = 0; i < p_array.Length; i++) {
if (elementi[i] != Int32.MaxValue && occorrenze[i] != Int32.MaxValue) { //mostro tutti gli elementi e le occorrenze che non siano il valore che ho escluso
Console.WriteLine($"L'elemento {elementi[i]} ricorre {occorrenze[i]} volte");
}
}
}
static void Pausa() {

BIN
bin/Debug/net9.0/interrogazione_1 Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"interrogazione_1/1.0.0": {
"runtime": {
"interrogazione_1.dll": {}
}
}
}
},
"libraries": {
"interrogazione_1/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

BIN
obj/Debug/net9.0/apphost Executable file

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("interrogazione_1")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d38856b73cb595d7894423740188b39c6fb3510a")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+39331d79c2ce0dbc1a252c8942adc30b1f54ae45")]
[assembly: System.Reflection.AssemblyProductAttribute("interrogazione_1")]
[assembly: System.Reflection.AssemblyTitleAttribute("interrogazione_1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
// Generato dalla classe WriteCodeFragment di MSBuild.

View File

@ -1 +1 @@
5eb9505a53b7be7239957238711ee9d545ae27922a39c4eb40cac9637ffa15ee
bc30cb61052e6223b011638802fec2b5eb489b9b7ae4390f67ab697fdedf08f4

View File

@ -0,0 +1 @@
03f850ed3e9c891a7c860466aa06c1f1a7e768ca3c08a85b2458e08890a36337

View File

@ -0,0 +1,14 @@
/home/Verde/git/interrogazione_1/bin/Debug/net9.0/interrogazione_1
/home/Verde/git/interrogazione_1/bin/Debug/net9.0/interrogazione_1.deps.json
/home/Verde/git/interrogazione_1/bin/Debug/net9.0/interrogazione_1.runtimeconfig.json
/home/Verde/git/interrogazione_1/bin/Debug/net9.0/interrogazione_1.dll
/home/Verde/git/interrogazione_1/bin/Debug/net9.0/interrogazione_1.pdb
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.GeneratedMSBuildEditorConfig.editorconfig
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.AssemblyInfoInputs.cache
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.AssemblyInfo.cs
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.csproj.CoreCompileInputs.cache
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.dll
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/refint/interrogazione_1.dll
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.pdb
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/interrogazione_1.genruntimeconfig.cache
/home/Verde/git/interrogazione_1/obj/Debug/net9.0/ref/interrogazione_1.dll

Binary file not shown.

View File

@ -0,0 +1 @@
2ec21e05c8a0643a873bc2e64aae0f5cb546c2cb2b6b40c9403a3c73e508a4a6

Binary file not shown.

Binary file not shown.

Binary file not shown.