For example:0 1 1 2 3 5 8 13......
Program:
#include <stdio.h>
void main()
{
int s=0,n,a,b;
a=0,b=1;
printf("enter any no:");
scanf("%d",&n);
printf("Fibonacci series:\n");
printf("%d",a);
printf("\t%d",b);
printf("\t");
for(int i=0;i<n;++i){
s=a+b;
a=b;
b=s;
printf("%d",s);
printf("\t");
}
}
Program:
#include <stdio.h>
void main()
{
int s=0,n,a,b;
a=0,b=1;
printf("enter any no:");
scanf("%d",&n);
printf("Fibonacci series:\n");
printf("%d",a);
printf("\t%d",b);
printf("\t");
for(int i=0;i<n;++i){
s=a+b;
a=b;
b=s;
printf("%d",s);
printf("\t");
}
}
No comments:
Post a Comment