37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
namespace ricorsione_3;
|
|
|
|
class Program {
|
|
static void Main(string[] args) {
|
|
Console.Write("Quanti numeri inserire? ");
|
|
int[] array = new int[Convert.ToInt32(Console.ReadLine())];
|
|
|
|
for (int i = 0; i < array.Length; i++) {
|
|
Console.Write($"Inserire il numero n. {i + 1}: ");
|
|
array[i] = Convert.ToInt32(Console.ReadLine());
|
|
}
|
|
|
|
int max = int.MinValue;
|
|
for (int i = 0; i < array.Length; i++) {
|
|
if (array[i] > max) {
|
|
max = array[i];
|
|
}
|
|
}
|
|
|
|
Console.WriteLine($"Massimo: {max}");
|
|
Console.WriteLine($"Massimo ricorsivo: {Ricorsione(array, int.MinValue, 0)}");
|
|
}
|
|
|
|
static int Ricorsione(int[] p_numeri, int p_max, int p_i) {
|
|
if (p_i == p_numeri.Length) {
|
|
return p_max;
|
|
}
|
|
else {
|
|
if (p_max == int.MinValue || p_numeri[p_i] > p_max) {
|
|
p_max = p_numeri[p_i];
|
|
}
|
|
}
|
|
return Ricorsione(p_numeri, p_max, p_i + 1);
|
|
}
|
|
|
|
}
|