Friday, 23 November 2012

Example:Program of Fibonacci Series and Lucas Series in C language


By on 00:28

Fibonacci Series:1 1 2 3 5 8 13 21...(means addition of next digit with previous digit).

Q)Write a program to enter limit and print the Fibonacci series.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,l,a,b,c;
printf("enter limit");
scanf("%d",&l);
a=0;
b=1;
printf("%d%d",a,b);
for(i=3;i<=l;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}

Lucas Series:1 3 4 7  11 18......(means addition of next digit with previous digit).


Q)Write a program to enter limit and print the Lucas series.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
Void main()
{
int i,l,a,b,c;
printf("enter limit");
scanf("%d",&l);
a=1;
b=3;
printf("%d%d",a,b);
for(i=3;i<=l;i++)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch();
}

If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...