19/04/2016

How to Find the Even Fibonacci in C++

This is the simple and logic building C++ exercise for beginners. The program will find the Even Fibonacci number in a given array.

Source Code 

#include <iostream>
using namespace std;
void welcomeScrean(void);
void evenFibonacci(void);

int main()
{
system ("color F0");

welcomeScrean();

evenFibonacci();

return 0;

}

void welcomeScrean(void){
cout<<"\a"
<<"\t*******************************************************"<<endl
<<"\t** **"<<endl
<<"\t** Welcome To **"<<endl
<<"\t** **"<<endl
<<"\t** Find Even Fibonacci **"<<endl
<<"\t** **"<<endl
<<"\t** and there sum **"<<endl
<<"\t** **"<<endl
<<"\t** Program **"<<endl
<<"\t** **"<<endl
<<"\t*******************************************************"<<endl
<<endl
<<endl;
}

void evenFibonacci(void){


int num,count=0;
long previous =1, next =0,sum;
cout<<"\t Enter Your Number to Find Fibonacci ";
cin>>num;

cout<<"\n\t First "<<num<<" Even Fibonacci Numbers Are \n";

do{
if(previous%2==0){
cout<<"\n\t "<<previous<<" ";
count++;
}
sum = previous+next;
next = previous;
previous = sum;

}while(count!=num);

}

Output of the Program

 Find the Even Fibonacci in C++

No comments:

Post a Comment