#include "stdio.h"
#include "string.h"
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
static int steps=1;//如果这里定义0就会少一步长,仔细想了下,还是没明白
main()
{
int step1,step2,n,stepsnum;
int x=2;//现在开始要走2个步长以上的了
int number=2;//第一和最后步是为1的
printf("put the two steps\n");
scanf("%d%d",&step1,&step2);
n=abs(step1-step2);
printf("%d\n",n);
if ((n-2)==1)
{
printf("the need %d steps between %d and %d\n",3,step1,step2);
getch();
return 0;
}
if ((n-2)==2)
{
printf("the need %d steps between %d and %d\n",3,step1,step2);
getch();
return 0;
}
stepsnum=fun(number,x,n);
printf("the steps is %d",stepsnum);
getch();
}
int fun(int number,int x,int n)
{
number+=x;
if (number<n)
{
steps++;
fun(number,x+1,n);//把里面的number ,x的数据都带到下一关计算
}
return steps+2;
}
我运行了几次,应该是行的,不知道有什么地方遗漏,望高手指点下
这是我的代码#include"stdio.h"
int f(int a,int b,double n)
{
if(n==1||n==2)
return 1;
else return (a* f(a,b,n - 1) + b * f(a,b,n - 2))% 7;
}
int main()
{ int A,B,z;
double n;
while( scanf("%d %d %lf",&A,&B,&n)&&A!=0&&B!=0&&n!=0&&n>=1)
{ z=f(A,B,n);
if((1 <= A&& A<=1000)&&(1 <= B&& B<=1000)&& (1 <= n&& n<=100000000))
printf("%d\n",z);
}
system("pause");
}