Skip to main content

Fibonacci Series, Prime Fibonacci Numbers

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

void fibonacci ( int );
void primefibo ( int );


void main()
{
  int n;
  printf("\n No. of Terms?:: ");
  scanf("%d",&n);
  fibonacci(n);
  printf("\n");
  primefibo(n);
}


// Function for displaying Fibonacci Series

void fibonacci(int n)
{
 int i=2,t0=0,t1=1,tn=1;
 printf("\n SERIES :: ");
 printf("%d  ",t0);
 while(i<n)
 {
  printf("%d  ",tn);
  tn=t0+t1;
  t0=t1;
  t1=tn;
  i++;
 }
 printf("%d",tn);
}


// Function for displaying Prime Numbers from Fibonacci Series

void primefibo ( int n )
{
 int i=2,t0=0,t1=1,tn=1;
 printf("\n Prime No. in SERIES :: ");
 while(i<n)
 {
  if(isprime(tn))
     printf("%d  ",tn);
  tn=t0+t1;
  t0=t1;
  t1=tn;
  i++;
 }
 if(isprime(tn))
    printf("%d",tn);
}



// Function to check a number whether it is Prime or not

int isprime( int n)
{
 int i;
 if(i<=1)
   return 0;
 for(i=2;i<n/2;i++)
  if(!(n%i))
   return 0;
 return 1;
}

Comments

Popular posts from this blog

Class Point:: It holds co-ordinates of a point in format (x,y)

A class Named "Point" which stores the Co-ordinates of a point in (x,y) Format. This Class Contains:: O Constructor with default arguments O Copy Constructor O Function to display which Co-ordinate a Point belongs to O Function to get value of x of a point O Function to get value of y of a point O Function to get the Radious Vector (r) of a point O Function to get the Theta of a point O Overloaded Operator - to find out distance between two points O Overloaded Operator >> to take input O Overloaded operator O Destructor #include<iostream.h> #include<math.h> class point{ //Data Members int x,y; //They hold the value of X and Y co-ordinate of a Point. public: //Member Functions point(int t1=0, int t2=0) //Constructor with default arguments. { x=t1; y=t2; } point(point &t) //Copy Constructor { x=t.x; y=t.y; } int coordinate(void); //It returns the point's Co-ordinate, e.g., 1, 2, 3, or 4th. int getx(...

Day of Week according to Date

We have 7 days in a week. And the first Day of the Date System is Sunday . And it should be. So, 01.01.0001, i.e., First Date of Christ was Sunday. We just number the days as follows. 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednessday 4 = Thursday 5 = Friday 6 = Saturday So, we can handle every day by the reminder of 7. Cause, u just see, after every 7 days the same day is repeated. Then, lets a rough Calculation. 01/01/0001 => Sunday = 0 Now, we just try to find out the day on 1st January on next year, i.e., 01/01/0002 0001 has 365 days. So, after 365 days which day will come? To find out the answer of this question we have to perform following calculation. 7 ) 365 ( 52 35 ----- 15 14 ---- 1 The reminder is 1, i.e.,Monday. But, using this method, it is very critical to find out the day of 1st January of 1988. So, we have an another idea. Find out how many Leap years are present before current year. Suppose it is L . So, L = y/4 If Current year is...