Thursday, 19 June 2014

C++ program to print non-Fibonacci numbers


Here is a C++ program to print non-Fibonacci numbers.


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    long n,a=0,b=1,temp=0,i,y=0;
    cout<<"Enter the value of n ";
    cin>>n;
    cout<<"non-Fibonacci series : ";
    for(int i=1;y<=n;i++)
    {
        if(temp<i)
        {
            temp=a+b;
            a=b;
            b=temp;
        }
        if(i!=temp)
        {
           cout<<i<<" ";
           y++;
        }
    }
    return 0;
}

Any questions regarding to program please write in comments.

1 comment: