Funzione CreaArrayCasuale (l'errore sulla classe Random non impedisce al programma di compilare)
This commit is contained in:
parent
097f3a4c93
commit
dbc865b3c7
51
Program.cs
51
Program.cs
@ -8,6 +8,7 @@ class Program
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
//dichiarazione e inizializzazione variabili
|
//dichiarazione e inizializzazione variabili
|
||||||
int scelta;
|
int scelta;
|
||||||
|
int[] array = new int [dimensione];
|
||||||
|
|
||||||
//menu
|
//menu
|
||||||
do{
|
do{
|
||||||
@ -24,12 +25,29 @@ class Program
|
|||||||
|
|
||||||
switch(scelta){
|
switch(scelta){
|
||||||
case 0:
|
case 0:
|
||||||
|
Console.Clear();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
Console.Clear();
|
||||||
|
array = CreaArrayCasuale();
|
||||||
|
StampaArray(array);
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
Console.Clear();
|
||||||
|
Pausa();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Errore: scelta non valida");
|
Console.WriteLine("Errore: scelta non valida");
|
||||||
Pausa();
|
Pausa();
|
||||||
@ -43,4 +61,37 @@ class Program
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int[] CreaArray(){
|
||||||
|
int[] ritorno=new int[dimensione];
|
||||||
|
int i=0;
|
||||||
|
string input;
|
||||||
|
|
||||||
|
do{
|
||||||
|
Console.Write("Inserire un numero, massimo " +dimensione+ " numeri ([q] per uscire): ");
|
||||||
|
input=Console.ReadLine(); //non posso ancora fare il catch dell'eccezione se viene inserito un qualcosa che non sia un numero o q
|
||||||
|
if(input!="q"){
|
||||||
|
ritorno[i]=Convert.ToInt32(input);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while(input!="q" && i<dimensione);
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int[] CreaArrayCasuale(){
|
||||||
|
Random caso = new Random();
|
||||||
|
int[] ritorno=new int[dimensione];
|
||||||
|
|
||||||
|
for(int i=0; i<dimensione; i++){
|
||||||
|
ritorno[i] = caso.Next(Int32.MinValue, Int32.MaxValue);
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void StampaArray(int [] p_insieme) {
|
||||||
|
for (int j=0; j<p_insieme.Length; j++){
|
||||||
|
Console.WriteLine("Elemento " +j+ ": " +p_insieme[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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.AssemblyCompanyAttribute("array_funzioni_4")]
|
||||||
[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+6c0811b572235bda9c94c60c6962e5b6d0e9dea5")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+097f3a4c93bebed479fb2426ed34e92ed4a21c8c")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("array_funzioni_4")]
|
[assembly: System.Reflection.AssemblyProductAttribute("array_funzioni_4")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("array_funzioni_4")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("array_funzioni_4")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
18df14bdc7b98b598854d00acc645ac0dd6581fd634c2bbfadde670c61420a84
|
2e185c028709242e0e13501e91f3c04f56d804222a54c2c1bd15e6e0f5c04cde
|
||||||
|
|||||||
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