u

Friday, 14 September 2012

C++ Program to display all prime fibonacci series within the range of 1 to 10000

C++ Program to display all prime fibonacci series within the range of 1 to 10000

#include<conio.h>
#include<iostream.h>
#include<stdio.h>
int isprime(int);
main()
{
clrscr();
cout<<"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;
}
getch();
}
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);
}
} 

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More