C++ Program to display Fibonacci numbers which are prime
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
// Declaration of the function
int isprime(int);
main()
{
clrscr();
int p,a=1,b=2,c=0;
p=isprime(a);// calling function
if (p==1) cout<<a<<" ";
p=isprime(b);// calling function
if (p==1) cout<<b<<" ";
while(c<=10000)
{
c=a+b;
p=isprime(c);
if((p==1) && (c<=10000))
cout<<c<<" ";
a=b;
b=c;
}
cout<<endl;
cout<<"Press any key to continue";
getch();
return 0;
}
// Defining the function
int isprime(int x)
{
int i;
if (x==1) return 0;
else
{
int pop=1;
for(i=2;i<x;i++)
{
if((x%i==0))
pop=2;
}
return pop;
}
}
Related Posts : C++ Programs
0 comments:
Post a Comment