Commenti e correzioni
This commit is contained in:
parent
8a3aaf0afa
commit
e31758ce5a
24
Program.cs
24
Program.cs
@ -8,7 +8,6 @@ class Program
|
||||
Console.Clear();
|
||||
//dichiarazione e inizializzazione variabili
|
||||
int scelta;
|
||||
int[] array = new int [dimensione];
|
||||
|
||||
//menu
|
||||
do{
|
||||
@ -94,11 +93,12 @@ class Program
|
||||
}
|
||||
|
||||
static int[] CreaArrayCasuale(){
|
||||
//dichiarazione e inizializzazione variabili
|
||||
Random caso = new Random();
|
||||
int[] ritorno = new int[dimensione];
|
||||
|
||||
for(int i=0; i<dimensione; i++){
|
||||
ritorno[i]=caso.Next(Int32.MinValue, Int32.MaxValue);
|
||||
ritorno[i]=caso.Next(Int32.MinValue, Int32.MaxValue);//per ogni posizione di ritorno assegno un valore a caso (metodo Random.Next)
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
@ -113,12 +113,12 @@ class Program
|
||||
int j = dimensione - 1, k = 0;
|
||||
for (int i=0; i<dimensione; i++){
|
||||
Console.Write("Elemento " + i + ": ");
|
||||
if(i%2 != 0){
|
||||
Console.WriteLine(p_array[j]);
|
||||
if(i%2 != 0){//se dispari. Con questa condizione posso stampare prima un elemento, poi l'ultimo, poi il secondo... incrementando di 1 i contatori invece che di 2
|
||||
Console.WriteLine(p_array[j]);//parto dall'ultimo elemento a scendere
|
||||
j--;
|
||||
}
|
||||
else{
|
||||
Console.WriteLine(p_array[k]);
|
||||
else{//se pari
|
||||
Console.WriteLine(p_array[k]);//parto dal primo elemento a salire
|
||||
k++;
|
||||
}
|
||||
}
|
||||
@ -127,12 +127,12 @@ class Program
|
||||
static string StampaPariDispari(int[] p_array){
|
||||
int sommaPari = 0, sommaDispari = 0, i = 0;
|
||||
string ritorno;
|
||||
while(i<dimensione){
|
||||
while(i<dimensione){//non è un ciclo for perché non posso aumentare il contatore di 2, ma solo di 1
|
||||
sommaPari = sommaPari + p_array[i];
|
||||
i = i + 2;
|
||||
}
|
||||
i = 1;
|
||||
while(i<dimensione){
|
||||
while(i<dimensione){//non è un ciclo for perché non posso aumentare il contatore di 2, ma solo di 1
|
||||
sommaDispari = sommaDispari + p_array[i];
|
||||
i = i + 2;
|
||||
}
|
||||
@ -150,7 +150,7 @@ class Program
|
||||
int j = dimensione - 1;
|
||||
|
||||
for(int i=0; i<dimensione; i++){
|
||||
ritorno[i] = p_array[j];
|
||||
ritorno[i] = p_array[j];//il primo elemento di ritorno è l'ultimo di p_array e così via, i e j variano in opposto
|
||||
j--;
|
||||
}
|
||||
return ritorno;
|
||||
@ -161,7 +161,7 @@ class Program
|
||||
int i = 0, j = 0;
|
||||
|
||||
while(consecutivo1==false && i<dimensione){
|
||||
while(consecutivo1==false && j<dimensione){
|
||||
while(consecutivo1==false && j<dimensione){//la prima condizione è ripetuta in modo da uscire subito dal ciclo per il primo consecutivo non appena viene trovato
|
||||
if (p_array[j] == p_array[i]+1){
|
||||
consecutivo1 = true;
|
||||
}
|
||||
@ -172,7 +172,7 @@ class Program
|
||||
}
|
||||
i = 0;
|
||||
j = 0;
|
||||
if(consecutivo1 == true){
|
||||
if(consecutivo1 == true){//se non ho trovato il primo consecutivo, non ha senso cercare per il secondo
|
||||
while(consecutivo2==false && i<dimensione){
|
||||
while(consecutivo2==false && j<dimensione){
|
||||
if (p_array[j] == p_array[i]+2){
|
||||
@ -198,7 +198,7 @@ class Program
|
||||
int i = 0, j = 0;
|
||||
|
||||
while(ritorno==false && i<dimensione){
|
||||
while(ritorno==false && j<dimensione){
|
||||
while(ritorno==false && j<dimensione){//la prima condizione è ripetuta in modo da uscire subito dal ciclo per il primo consecutivo non appena viene trovato
|
||||
if (p_array[j] == p_array[i]*2){
|
||||
ritorno = true;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("array_funzioni_4")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+dff4366e30e266315f0fd967ab16d8509d629273")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8a3aaf0afae11df9d0db15dade17941d33b9ad89")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("array_funzioni_4")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("array_funzioni_4")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
ca299e75237115b1e692d48d36398c1c127ee21df577772c1d66b6dd45a45494
|
||||
ef445b7a3be0da6880356bea77e55ef330fda7c52d5391fbb6a24eeab9e69233
|
||||
|
||||
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