#include<stdio.h>
#include<conio.h>
void main(){
int n;
void fibonacci(int);
clrscr();
printf("How many numbers do you want in fibonacci series\n");
scanf("%d",&n);
fibonacci(n);
getch();
}
void fibonacci(int x){
int i;
float a,b,c;
if(x>0){
printf("Enter 2 intial number of series\n");
scanf("%f %f",&a,&b);
printf("Fibonacci series of %d numbers\n",x);
if (x==1) printf("%.2f",a);
else {
if (x==2) printf("%.2f %.2f ",a,b);
else {
printf("%.2f %.2f ",a,b);
for (i=1;i<=x-2;i++) {
c=a+b;
printf("%.2f ",c);
a=b;
b=c;
}}}}
else printf("Wrong input\nTry again!!\n");
}
No comments:
Post a Comment