Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(Part-2)
TO GENERATE THE FIBONACCI SERIES & FINDING THE
PRIME NUMBERS
STATEMENT:
ALGORITHM:
OUTPUT: Fibonacci series with ‘n’ elements and generating prime numbers
from the Fibonacci series.
PROCESS:
Step 1.1: Take the number of terms from user in an integer type variable ‘n’.
Step 1.2: Print initial two Fibonacci numbers ‘0’ and ‘1’ which were
initialized to two integer type variable ‘a’ and ‘b’ i.e. print “a , b”.
Step 1.3: For i=0 to (n-3) repeat Step 1.4 to Step 1.14
Break
[End of ‘If’]
Step 1.15: Print the integer type array ‘d’ to display the prime numbers
generated by the Fibonacci series.
Step 2: Stop
PROGRAM CODE:
/* FIBONACCI NUMBER */
#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,i,c,n,p,j,d[50],k=0;
printf("Enter the number of terms:");
for(i=0;i<n-2;i++)
{
c=a+b;
printf("%d ",c);
p=c;
if(p>1)
{
for(j=2;j<=p/2;j++)
{
if(p%j==0)
break;
}
if(j>p/2)
{
d[k]=p;
k++;
}
}
a=b;
b=c;
}
for(j=0;j<k;j++)
printf("%d, ",d[j]);
getch( );
}