Sommatoria di un numero

Questa funzione restituisce la sommatoria di un numero. Per esempio la sommatoria di 6 è uguale a: 6+5+4+3+2+1=21

'*********************************************
'num = numero
'*********************************************

Function Sommatoria(num As Integer) As Double
If num = 0 Then
    Sommatoria = 0
Else
    Sommatoria = num + Sommatoria(num - 1)
End If
End Function

Testato su: Tutti i Sistemi operativi