ppt编程题——函数 (输出杨辉三角未写)
#include<stdio.h>
int fib(int n);
void move(char from,char to);
void hanoi(int n,char one,char two,char three);
void er(int n);
double fac(double n);
void mws(int n);
int main()
{
int n;
scanf("%d",&n);
printf("%.0lf\n",(n));
// er(n);
// hanoi(n,‘A’,‘B’,‘C’);
// mws(125);
return 0;
}
int fib(int n) //Fibonacci斐波那契数列的第n项
{
if(n1||n2)return 1;
int f1=1,f2=1,f,t;
for(int i=3;i<=n;i++) //迭代法
{
f=f1+f2;
t=f1;
f1=f;
f2=t;
};
return f;
}
void hanoi(int n,char one,char two,char three)//汉诺塔问题Hanoi 递归
{
if(n==1) move(one,three) ;
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char from,char to)//汉诺塔问题Hanoi中的移动函数
{
printf("%c--->%c\n",from,to);
}
void er(int n)//一个正整数的二进制
{
if(n<2)printf(“二进制为:%d”,n);
else
{
er(n/2);
printf("%d",n%2);
}
}
double fac(double n)//阶乘 的迭代 算法
{
double sum=1;
for(double i=1;i<=n;i++)
{
sum=sum*i;
}
return sum;
}
void mws(int n) //递归求一个数的每一位
{
if(n<10)printf(" %d",n);
else
{
mws(n/10);
printf(" %d",n%10);
}
}
int Pyhsj(int n) //输出杨辉三角 ???
{
for(int i=1;i<=n;i++)
{
for(int j)
}
}

浙公网安备 33010602011771号