Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:10:30+00:00 2026-06-18T00:10:30+00:00

Starter with the logic implementation through programming so please find my honest efforts for

  • 0

Starter with the logic implementation through programming so please find my honest efforts for project Euler Ques, although i tried various attempts to solve but could not get through it 🙁

Sum I am getting from this is – 257112. I added +2 in the sum to count for a[1] = 2 in the series, but its not working, also I am currently passing a static value 45 for $num but i think it is not the correct way, let me know where I am lagging in logic for the question.

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, …

By considering the terms in the Fibonacci sequence whose values do not
exceed four million, find the sum of the even-valued terms.

this is the code I tried –>

$a = array();
$a[0] = 1; $a[1] = 2; $num = 45; $i= 0; $sum = 0; $stop = $num -2;
    for($i; $i < $stop ; $i++ ) {
    $a[$i+2] = $a[$i+1] + $a[$i];

            if( $a[$i+2]%2 == 0 && $a[$i+2] <= 400000 )
            {
            $sum += $a[$i+2]; 
            }

    }

echo "<pre>";
print_r($a);
echo "<br>"."Sum is : ".$sum;

EDIT – It was an error to add an extra zero to make it 4 million, although I am looking something for $num not to be static (as 45 I just mentioned randomly, although its working but its not a clean solution)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:10:32+00:00Added an answer on June 18, 2026 at 12:10 am

    Make it simple, no arrays and make it quick. You are only looking for the sum, nothing else:

    $a=1;$b=2;$sum=2;
    while($b<4000000){
        $c=$b+$a;
        if($c%2==0)
            $sum+=$c;
        $a=$b;
        $b=$c;
    }
    echo $sum;
    

    If 4,000,000 counted, then it would be $b<=4000000

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a starter in Objective-C and IOS programming, and I'd like to have some
I'm creating a starter kit that installs the compiled assemblies from an open-source project
I’m having a little Architecture problem. In my project I have a Business Logic
i starter in jqgrid, i want implement inline edit in jqgrid i have this
i'm starter in linq and EF. i Have 4 table CurrencyUnit CurrencyUnitID CurrencyName -------------------------------
i'm starter in jqgrid, i write this code for create and fill jqgrid(i'm use
Delphi XE2 starter for me, but maybe a general answer will help others ...
Still an iphone dev starter but trying. I would like to have the user
In my simple starter asp page I create a DataTable and populate it with
A number of people are unhappy with the current implementation where there are either

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.