[求助]自己编写的斑竹请看看对不对
1、请编制递归函数fabonacci(),此函数用来求斐波那契数列的第n项?
#include <stdio.h>
int fib(int n)
{
if(n<=2)
return(1);
else
return(fib(n-1)+fib(n-2));
}
void main()
{
int n;
do
{
printf("\nInput n(1-40):\n");
scanf("%d",&n);
}while(n<=0||n>40);
printf("\nThe result is:%ld\n",fib(n));
}
2、编制函数min(),求三个小数的最小值?
#include <stdio.h>
float min(float,float,float);
void main()
{
float a,b,c;
printf("Input a b c:");
scanf("%f%f%f",&a,&b,&c);
printf("Minimum number is:%f",min(a,b,c));
}
float min(float a,float b,float c)
{
if(a<b)
if(a<c)
return a;
else
return c;
else
if(b<c)
return b;
else
return c;
}