WAP to print fibonacci series till n terms
#include <conio.h>
void main()
{
int n,a=0,b=1,c=0;
printf("Enter the number of terms");
scanf("%d",&n);
printf("%d %d ",a,b);
for(int i=3;i<=n;i++)
{
c=a+b;
printf("%d ",c);
a=b;
b=c;
}
}
Example: n=6
Output:0 1 1 2 3 5
#include <stdio.h>#include <conio.h>
void main()
{
int n,a=0,b=1,c=0;
printf("Enter the number of terms");
scanf("%d",&n);
printf("%d %d ",a,b);
for(int i=3;i<=n;i++)
{
c=a+b;
printf("%d ",c);
a=b;
b=c;
}
}
No comments:
Post a Comment