Showing posts with label Fibonacci. Show all posts
Showing posts with label Fibonacci. Show all posts

Wednesday, September 19, 2012

Program to display all prime fibonacci series, between 1 to 10000

#include<iostream>
#include<cstdio>
using namespace std;

int isprime(int);

int main()
{
    cout << "\n All prime fibonacci series in the range of 1 to 10000 are" << endl;
    int r;
    int a = 1,b = 2,c = 0;
    r = isprime(a);
    if (r == 1) cout << a <<" ";
    r = isprime(b);
    if (r==1) cout << b <<" ";
    while (c <= 10000)
    {
        c = a+b;
        r = isprime(c);
        if ((r == 1) && (c <= 10000))
        cout << c <<" ";
        a = b;
        b = c;
    }
    return 0;
}

int isprime(int x)
{
    int i;
    if (x == 1) return 0;
    else
    {
        int p = 1;
        for(i=2; i<x; i++)
        {
            if (x%i==0)
            p=2;
        }
        return (p);
    }
}


OUTPUT:

Wednesday, July 11, 2012

A program to print febonacci series upto first 20 trems

#include <stdio.h>
#include <conio.h>

int main()
{
    int a = 0;
    int b = 1;
    int i,sum;
    
    for(i = 0;i<20;i++)
    {
        sum = a+b;
        printf("%d\n",sum);
         
        a = b;
        b = sum;
    }
}

A program to print the FIBONACCI series


#include<iostream>
using namespace std;

main()
{
   int n, c, first = 0, second = 1, next;

   cout << "Enter the number of terms of Fibonacci series you want" << endl;
   cin >> n;

   cout << "First " << n << " terms of Fibonacci series are :- " << endl;

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;


      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      cout << next << endl;
   }
}