I'm basically done with this, the only problem is when it loops to check for the prime number, it prints out prime numbers that are not in the Fibonacci sequence as well. Here is my code:
int main()
{
int no1,no2,newno,pno,i,terms,j;
no1 = 0;
no2 = 1;
printf("**Fibonacci and Prime Numbers**\n\n");
printf("Enter number of terms: \n");
scanf("%d", &terms);
printf("\nAmong the first %d terms of Fibonacci series that are also prime number: \n", terms);
for(i=0; i<terms; i++){
if(i<=no2){
newno = i;
}
else{
newno = no1+no2;
no1 = no2;
no2 = newno;
}
}
for(pno=2;pno<=newno;pno++){
for(j=2;j<=pno;j++){
if(pno%j==0){
break;
}
}
if(pno==j){
printf("%d \n", pno);
}
}
getch();
return 0;
}
I'm guessing its because of the pno++
, Am i right?