Opzione 1 perfezionata
This commit is contained in:
parent
086b21dd79
commit
3efdd8911e
44
Program.cs
44
Program.cs
@ -55,9 +55,10 @@ class Program {
|
||||
Console.Clear();
|
||||
}
|
||||
static int[] CreaArray() {
|
||||
int dimensione, input, i = 0;
|
||||
int dimensione, i = 0;
|
||||
string input;
|
||||
|
||||
do {
|
||||
do { //richiesta dimensione array
|
||||
Console.Write("Quanti numeri vuoi inserire? ");
|
||||
dimensione = Convert.ToInt32(Console.ReadLine());
|
||||
if (dimensione <= 0) {
|
||||
@ -68,30 +69,39 @@ class Program {
|
||||
|
||||
int[] ritorno = new int[dimensione];
|
||||
|
||||
do {
|
||||
for (i = 0; i < dimensione; i++) {//creo un valore di default, così la sequenza non deve essere per forza completa
|
||||
ritorno[i] = -1;
|
||||
}
|
||||
|
||||
i = 0;//reset contatore
|
||||
|
||||
do{//richiesta numeri da mettere nell'array
|
||||
Console.Clear();
|
||||
Console.WriteLine("Hai ancora " + (dimensione - i) + " numeri da inserire");
|
||||
Console.Write("Inserire un numero: ");
|
||||
|
||||
input = Convert.ToInt32(Console.ReadLine());
|
||||
|
||||
if (input >= minDimensione && input <= maxDimensione) {
|
||||
ritorno[i] = input;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Il numero deve essere compreso tra 0 e 100, estremi inclusi");
|
||||
Pausa();
|
||||
Console.Write("Inserire un numero ([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"){
|
||||
if(Convert.ToInt32(input) >= minDimensione && Convert.ToInt32(input) <= maxDimensione){
|
||||
ritorno[i]=Convert.ToInt32(input);
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Il numero deve essere compreso tra 0 e 100, estremi inclusi");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
while (i < dimensione);
|
||||
while(input!="q" && i<dimensione);
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
static void StampaArray(int[] p_insieme) {
|
||||
for (int j = 0; j < p_insieme.Length; j++) {
|
||||
|
||||
Console.WriteLine("Elemento " + j + ": " + p_insieme[j]);
|
||||
if (p_insieme[j] != -1) {
|
||||
Console.WriteLine("Elemento " + j + ": " + p_insieme[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2246c2a5c095c6bb71e6a33099cf80c27409746d")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+086b21dd793eaa17d118504d46c1e2453b3e6c2e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
aaa763a7affc3371615bd6044c96dcccc53eb0bb19d6f3126b512213bb9adcb3
|
||||
ac2921e05374effe4e870836228f7bfb3b5cb46f2517248564fe24fc495f7806
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user