Sunday 24 August 2014

Lucas Series

Q:- Write a program in C to generate Lucas Series.

Lucas number is defined to be the sum of its two immediate previous terms, thereby forming a Fibonacci integer sequence. The first two Lucas numbers are L0 = 2 and L1 = 1 as opposed to the first two Fibonacci numbers F0 = 0 and F1 = 1. Though closely related in definition, Lucas and Fibonacci numbers exhibit distinct properties.
The Lucas numbers may thus be defined as follows:
 
  L_n :=
  \begin{cases}
    2               & \text{if } n = 0; \\
    1               & \text{if } n = 1; \\
    L_{n-1}+L_{n-2} & \text{if } n > 1. \\
   \end{cases}
The sequence of Lucas numbers is:
2,\;1,\;3,\;4,\;7,\;11,\;18,\;29,\;47,\;76,\;123,\; \ldots\;


#include<conio.h>
#include<stdio.h>
void main( )
{
int lmt,x=0,y=1,z=0,a=0;
clrscr( );
printf("\nEnter the limit");
scanf("%d",&lmt);
while(a<=lmt)
   {
    printf("\n%d",a);
    x=y;
    z=a;
    a=x+y+z;
    }
getch( )
}

No comments:

Post a Comment

Tell Us What You've Got...