How to Calculate Fibonacci Sequence Sum of Even Values

Core

Member
Jan 23, 2010
3,120
195
0
Milky Way/Local Cluster/Local Sol/Earth
Hello! This is what I have done to Solve the Fibonacci Sequence Sum of Even Values

:)

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem_2
{
class Program
{
static void Main(string[] args)
{
uint y = 0, preA = 0, A = 0 ,temp = 0 ,sumVal=0;
y = 1; preA = 1;

Console.WriteLine("Write the Max Boundary of Fibonacci Sequence");
uint _Max = uint.Parse(Console.ReadLine());
Console.WriteLine();

while (A < _Max)
{
A = y + preA;
y = preA;
preA = A;

if (A % 2 == 0)
{
sumVal = A;
sumVal += temp;
temp = sumVal;
Console.WriteLine(sumVal);
}
}
Console.ReadLine();

}
}
}



C++

#include <iostream>

using namespace std;

int main()
{
unsigned y = 0, preA = 0, A = 0 ,temp = 0 ,sumVal=0;
y = 1; preA = 1;

cout << endl << "Write the Max Boundary of Fibonacci Sequence";
cout << endl;
int num=0;
cin >> num;
unsigned _Max = static_cast<unsigned>(num);
cout << endl;

while (A < _Max)
{
A = y + preA;
y = preA;
preA = A;

if (A % 2 == 0)
{
sumVal = A;
sumVal += temp;
temp = sumVal;
cout << sumVal << endl;
}
}
cin >> num;

}



Ask please before using my codes
cause I worked couple of hours to solve this Question.


All Codes belong to the Original Author (Core Elakiri)

No Reference.!