Options: Télécharger en PDF | Télécharger la pièce jointe | Numérotation des lignes
| Type: |
sub |
| Ajouté par: |
Rembo |
| Courte Description: |
From their website:
"What is Project Euler?
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.
The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context."
After reading some of the solutions discussed in Dick's blog I thought it would be fun to post some solutions on this website as well. Rather than copying and pasting solutions of other people I will post my own solution. They may not be the most efficient solutions but they do the job. The challenge is of course to find your own solution, although the use of the internet is encouraged. Please see the Project Euler website for a full explanation.
If you find this challenging I encourage you to sign up (free) and see how far you get with programming your VBA solution. |
| Détails: |
The problem description is included with the code. |
| Ajouté le: |
05 fév 2009 à 12h02 |
| Liens connexes |
http://projecteuler.net
|
Run the routine, the answer is printed in the debugging screen.
Sub Euler_0002()
'Each new term in the Fibonacci sequence is generated by adding the previous two terms.
'By starting with 1 and 2, the first 10 terms will be:
'
'1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
'
'Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Dim i1 As Long, i2 As Long, iTemp As Long, iTotal As Long
i1 = 1
i2 = 2
iTotal = 2
While i2 <= 4000000
iTemp = i1 + i2
i1 = i2
i2 = iTemp
If i2 Mod 2 = 0 Then
iTotal = iTotal + i2
End If
Wend
Debug.Print iTotal
End Sub