- 河内之塔(Towers of Hanoi)
#include <stdio.h>
void hanoi_recursive(int n, char A,char B,char C){
if (n==1)
{
printf("Move sheet %d from %c to %c",n,A,C);
}
else{
hanoi_recursive(n-1,A,C,B);
printf("Move sheet %d from %c to %c \n",n,A,C);
hanoi_recursive(n-1,B,A,C);
}
}
int TowerOfHanoi(){
int n;
printf("请输入整数:");
scanf("%d",&n);
hanoi_recursive(n,'A','B','C');
return 0;
}
- 费氏数列
#include <stdio.h>
#include <stdlib.h>
#define N0 20
int Fibonacci()
{
int Fib[N0] = {0};
int i;
Fib[0] = 0;
Fib[1] = 1;
for (i = 2; i < N0; i++)
{
Fib[i] = Fib[i - 1] + Fib[i - 2];
}
for (i = 0; i < N0; i++)
{
printf("%d ", Fib[i]);
printf("\n");
}
return 0;
}