#include < stdio.h >
#include < time.h >
long double fib(int);
void main()
{
int i,n;
long double f;
long int t1,t2,t3,*t=NULL;
char ch;
do
{
clrscr();
printf("\nenter upper limit : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
t1=time(t);
f=fib(i);
t2=time(t);
t3=t2-t1;
printf("fib(%3d) = %30.0Lf time = %ld sec\n",i,f,t3);
}
printf("\ndo you want to continue (y/n?) : ");
ch=getch();
}while(ch=='y'||ch=='Y');
}
long double fib(int n)
{
if(n<=2)
return 1;
else
return n=fib(n-1)+fib(n-2);
}
#include < time.h >
long double fib(int);
void main()
{
int i,n;
long double f;
long int t1,t2,t3,*t=NULL;
char ch;
do
{
clrscr();
printf("\nenter upper limit : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
t1=time(t);
f=fib(i);
t2=time(t);
t3=t2-t1;
printf("fib(%3d) = %30.0Lf time = %ld sec\n",i,f,t3);
}
printf("\ndo you want to continue (y/n?) : ");
ch=getch();
}while(ch=='y'||ch=='Y');
}
long double fib(int n)
{
if(n<=2)
return 1;
else
return n=fib(n-1)+fib(n-2);
}
No comments:
Post a Comment