/* program to generate fibonacii series
1,1,2,3,5,8,13,34,........
in this series each number is a sum of the previous two numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
long int x,y,z;
int i,n;
x=0;
y=1;
printf("Enter the number of terms :");
scanf("%d",&n);
printf("%ld ",y);
for(i=0;i<n;i++)
{
z=x+y;
printf("%ld ",z);
x=y;
y=z;
}
printf("\n");
getch();
}
1,1,2,3,5,8,13,34,........
in this series each number is a sum of the previous two numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
long int x,y,z;
int i,n;
x=0;
y=1;
printf("Enter the number of terms :");
scanf("%d",&n);
printf("%ld ",y);
for(i=0;i<n;i++)
{
z=x+y;
printf("%ld ",z);
x=y;
y=z;
}
printf("\n");
getch();
}
No comments:
Post a Comment