标签:class scanf i++ return ota 台阶 int pre print
#include<stdio.h>
#include<stdlib.h>
//n的阶乘
int f(int n)
{
if(1==n)
{
return 1;
}
return n*f(n-1);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d!=%d\n",n,f(n));
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
int step(int n)
{
if(1==n)
{
return 1;
}
if(2==n)
{
return 2;
}
return step(n-1)+step(n-2);
}
int main()
{
int i,n;
int first,second,total;
printf("请输入台阶数:");
while(scanf("%d",&n)!=EOF)
{
printf("第%d阶台阶有%d种走法\n",n,step(n));
}
system("pause");
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,n;
int first,second,total;
printf("请输入台阶数:");
while(scanf("%d",&n)!=EOF)
{
first=0;
second=1;
for(i=1; i<=n; i++)
{
total=first+second;
first=second;
second=total;
}
printf("%d!=%d\n",n,total);
}
system("pause");
}
标签:class scanf i++ return ota 台阶 int pre print
原文地址:https://www.cnblogs.com/buxiu888/p/14110529.html