Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Christmas Math Fun
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00064933
Message ID:
00065046
Vues:
31
>On the 1st day of Xmas, my true love gave to me:
>1 item
>On the 2nd day of Xmas, my true love gave to me:
>2 items + 1 item
>On the 3rd day of Xmas, my true love gave to me:
>3 items + 2 items + 1 item
>.
>.
>On the n-1 day of Xmas, my true love gave to me:
>n-1 items + n-2 items + ... + 1 item
>On the nth day of Xmas, my true love gave to me:
>n items + n-1 items + ... + 1 item
>
>How many total items did my true love give to me, as a function of n?

OK, Bruce, you said no looping, but you didn't say no recursion:

FUNCTION Gifts

LPARAMETER pnDays

LOCAL lnresult
lnresult = 0
IF pnDays > 0
lnresult = ((pnDays * (pnDays + 1 ) ) / 2) + Gifts(pnDays - 1)
ENDIF
RETURN lnresult
ENDFUNC

:-)

George
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform