Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- // Problème Euler 2
- void main(){
- immutable uint MAX = 4_000_000;
- uint[] tableau = new uint[] (5);
- tableau[0] = 1;
- tableau[1] = 2;
- uint somme = 0;
- // On va mettre ici la séquence des termes
- ushort i = 1, j; // On va commencer à tableau[2] quand même ;)
- while(tableau[i] < MAX - tableau[i-1]){ // Sans la soustraction, on dépasse le MAX
- if(i == tableau.length-1) // -1 car après on accède à tableau[i+1] qui existe pas encore
- tableau.length *= 2;
- tableau[i+1] = tableau[i-1] + tableau[i];
- //somme += tableau[i+1];
- i++;
- }
- foreach(ligne; tableau[])
- writeln(ligne);
- writeln("---------");
- for(i = 1; i <= tableau.length-2; i+=2 )
- somme += tableau[i];
- write( "Somme des nombres pairs : " , somme);
- }
Add Comment
Please, Sign In to add comment