Q:- Write a program in C to generate Lucas Series.
#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( )
}
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:
The sequence of Lucas numbers is:
#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...